201 lines
7.6 KiB
C#
201 lines
7.6 KiB
C#
/*
|
||
* @Author: 白哉
|
||
* @Description: 行为逻辑类
|
||
* @Date: 2025年04月10日 星期四 11:04:44
|
||
* @Modify:
|
||
*/
|
||
|
||
|
||
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Logic.Action;
|
||
using RuntimeData;
|
||
using TH1_Logic.Core;
|
||
using TH1Renderer;
|
||
using UnityEngine;
|
||
|
||
|
||
//这里是所有BuildAction派生子类的实现模块
|
||
namespace TH1_Logic.Action
|
||
{
|
||
|
||
public enum PlayerActionType
|
||
{
|
||
None,
|
||
OfferAlly,
|
||
AcceptAlly,
|
||
RefuseAlly,
|
||
BreakAlly,
|
||
Embassy
|
||
}
|
||
|
||
//UnitAction单位行动逻辑类
|
||
public class PlayerActionAction : ActionLogicBase
|
||
{
|
||
public PlayerActionAction(CommonActionId id) : base(id)
|
||
{
|
||
|
||
}
|
||
|
||
public override bool Execute(CommonActionParams actionParams, bool isMoment)
|
||
{
|
||
//鲁棒性判断
|
||
bool ret = false;
|
||
return ret;
|
||
}
|
||
|
||
public override bool CheckCan(CommonActionParams actionParams)
|
||
{
|
||
|
||
//Step #1 鲁棒性判断
|
||
if (actionParams.PlayerData == null) return false;
|
||
if (actionParams.MainObjectType != MainObjectType.Player) return false;
|
||
if (actionParams.TargetPlayerData == null) return false;
|
||
|
||
//Step #2 判断钱够不够
|
||
if (GetCost() > actionParams.PlayerData.PlayerWealth)
|
||
return false;
|
||
//Step #3 如果不具备科技 return
|
||
if (!actionParams.PlayerData.TechTree.CheckActionCan(_actionId))
|
||
return false;
|
||
|
||
//Step #4 处理大使馆
|
||
if (_actionId.PlayerActionType == PlayerActionType.Embassy)
|
||
{
|
||
//如果对方没有原始首都,不可建立大使馆
|
||
actionParams.MapData.GetCapitalCityDataByPlayerId(actionParams.TargetPlayerData.Id,out var city);
|
||
if (!Main.CityLogic.CheckCradleCapital(actionParams.MapData, actionParams.TargetPlayerData, city))
|
||
return false;
|
||
|
||
//如果已经在对方建立了大使馆,不可再次建立大使馆
|
||
actionParams.PlayerData.DiplomacyData.GetCountryDiplomacyInfo(actionParams.TargetPlayerData.Id, out var dipInfo);
|
||
if (dipInfo.IsEmbassy) return false;
|
||
return true;
|
||
}
|
||
|
||
//Step #5 判断能否申请结盟
|
||
if (_actionId.PlayerActionType == PlayerActionType.OfferAlly)
|
||
{
|
||
actionParams.PlayerData.DiplomacyData.GetCountryDiplomacyInfo(actionParams.TargetPlayerData.Id, out var dipInfo);
|
||
//如果刚解除结盟或者已经结盟 return
|
||
if (dipInfo.DiplomacyState == DiplomacyState.League ||
|
||
dipInfo.DiplomacyState == DiplomacyState.LeagueRupture)
|
||
return false;
|
||
|
||
//如果对方已经有一个来自我方的结盟请求
|
||
actionParams.TargetPlayerData.DiplomacyData.GetCountryDiplomacyInfo(actionParams.PlayerData.Id,out var dipInfo2);
|
||
if (dipInfo2.IsLeagueRequest) return false;
|
||
|
||
return true;
|
||
}
|
||
//Step #6 判断能否refuse结盟
|
||
if (_actionId.PlayerActionType == PlayerActionType.OfferAlly)
|
||
{
|
||
actionParams.PlayerData.DiplomacyData.GetCountryDiplomacyInfo(actionParams.TargetPlayerData.Id, out var dipInfo);
|
||
//如果刚解除结盟或者已经结盟 return
|
||
if (dipInfo.DiplomacyState == DiplomacyState.League ||
|
||
dipInfo.DiplomacyState == DiplomacyState.LeagueRupture)
|
||
return false;
|
||
|
||
//如果对方没有结盟请求
|
||
actionParams.TargetPlayerData.DiplomacyData.GetCountryDiplomacyInfo(actionParams.PlayerData.Id,out var dipInfo2);
|
||
if (!dipInfo2.IsLeagueRequest) return false;
|
||
return true;
|
||
}
|
||
|
||
//Step #7 判断能否break结盟
|
||
if (_actionId.PlayerActionType == PlayerActionType.OfferAlly)
|
||
{
|
||
actionParams.PlayerData.DiplomacyData.GetCountryDiplomacyInfo(actionParams.TargetPlayerData.Id, out var dipInfo);
|
||
//如果没有结盟 return
|
||
if (dipInfo.DiplomacyState != DiplomacyState.League) return false;
|
||
//如果对方率先break,return
|
||
actionParams.TargetPlayerData.DiplomacyData.GetCountryDiplomacyInfo(actionParams.PlayerData.Id,out var dipInfo2);
|
||
if (dipInfo2.DiplomacyState == DiplomacyState.LeagueRupture) return false;
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
public override bool CheckShow(CommonActionParams actionParams)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
public override bool ExecuteViewBefore(CommonActionParams actionParams)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
public override bool ExecuteViewAfter(CommonActionParams actionParams)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
//付钱
|
||
protected bool UnitActionPayMoney(CommonActionParams actionParam)
|
||
{
|
||
if (actionParam.PlayerData.PlayerWealth - GetCost() < 0) return false;
|
||
actionParam.PlayerData.PlayerWealth -= GetCost();
|
||
return true;
|
||
}
|
||
|
||
//确认是否满足基本信息,并且补全actionParam(主要是补充unit所处的grid)
|
||
protected bool UnitActionCheckBaseInfo(CommonActionParams actionParam)
|
||
{
|
||
//鲁棒性判断,必须包含unitData和playerData,表明是哪个玩家正在操作哪个单位
|
||
if (actionParam.UnitData == null) return false;
|
||
if (actionParam.PlayerData == null) return false;
|
||
if (!actionParam.MapData.GetGridDataByUnitId(actionParam.UnitData.Id, out var grid)) return false;
|
||
actionParam.GridData = grid;
|
||
return true;
|
||
}
|
||
protected bool UnitActionCheckUnitBelongPlayer(CommonActionParams actionParam)
|
||
{
|
||
//如果unit不是player的,退出
|
||
if(!actionParam.MapData.GetPlayerDataByUnitId(actionParam.UnitData.Id, out var playerData) ||
|
||
playerData != actionParam.PlayerData)
|
||
return false;
|
||
return true;
|
||
}
|
||
//确认是否有科技
|
||
protected bool UnitActionCheckHasTech(CommonActionParams actionParam)
|
||
{
|
||
//如果没有对应科技,return false
|
||
if (!actionParam.PlayerData.TechTree.CheckActionCan(_actionId))
|
||
return false;
|
||
return true;
|
||
}
|
||
|
||
//确认是否有钱
|
||
protected bool UnitActionCheckHasMoney(CommonActionParams actionParam)
|
||
{
|
||
//判断钱够不够
|
||
if (GetCost() > actionParam.PlayerData.PlayerWealth)
|
||
return false;
|
||
return true;
|
||
|
||
}
|
||
|
||
//确认unit是否有CP
|
||
protected bool UnitActionCheckUnitHasCP(CommonActionParams actionParam)
|
||
{
|
||
if (actionParam.UnitData == null || actionParam.UnitData.CP <= 0)
|
||
return false;
|
||
return true;
|
||
}
|
||
|
||
//确认unit是否拥有这个skill
|
||
protected bool UnitActionCheckUnitHasSkill(CommonActionParams actionParam)
|
||
{
|
||
//将unitActionType转化为skillType
|
||
if (!Enum.TryParse(_actionId.UnitActionType.ToString(), out SkillType skillType)) return false;
|
||
if (actionParam.UnitData == null || !actionParam.UnitData.GetSkill(skillType, out var _)) return false;
|
||
return true;
|
||
}
|
||
|
||
}
|
||
|
||
} |