public static void Awake(this NumericComponent self, int typeId) { // 这里初始化base值 UnitConfig unitConfig = Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), typeId) as UnitConfig; self.Set(NumericType.ArmorResist, unitConfig.ArmorResist); self.Set(NumericType.ATK, unitConfig.ATK); self.Set(NumericType.CritDamagePct, (float)unitConfig.CritDamagePct); self.Set(NumericType.CritRate, (float)unitConfig.CritRate); self.Set(NumericType.DodgeRate, (float)unitConfig.DodgeRate); self.Set(NumericType.HitRate, (float)unitConfig.HitRate); self.Set(NumericType.HP, unitConfig.HPMax); self.Set(NumericType.HPMax_Base, unitConfig.HPMax); self.Set(NumericType.HP_LeechRate, (float)unitConfig.HP_LeechRate); self.Set(NumericType.HP_Restore, unitConfig.HP_Restore); self.Set(NumericType.Level, unitConfig.Level); self.Set(NumericType.MagicATK, unitConfig.MagicATK); self.Set(NumericType.MagicResist, unitConfig.MagicResist); self.Set(NumericType.MoveSpeed, (float)unitConfig.MoveSpeed); self.Set(NumericType.MP, unitConfig.MPMax); self.Set(NumericType.MPMax_Base, unitConfig.MPMax); self.Set(NumericType.MP_LeechRate, (float)unitConfig.MP_LeechRate); self.Set(NumericType.MP_Restore, unitConfig.MP_Restore); }
public static Unit Create(Scene scene, long id, UnitType unitType) { UnitComponent unitComponent = scene.GetComponent <UnitComponent>(); switch (unitType) { case UnitType.Player: { Unit unit = unitComponent.AddChildWithId <Unit, int>(id, 1001); unit.AddComponent <MoveComponent>(); unit.Position = new Vector3(-10, 0, -10); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); numericComponent.Set(NumericType.Speed, 6f); // 速度是6米每秒 numericComponent.Set(NumericType.AOI, 15000); // 视野15米 unitComponent.Add(unit); // 加入aoi unit.AddComponent <AOIEntity, int, Vector3>(9 * 1000, unit.Position); return(unit); } default: throw new Exception($"not such unit type: {unitType}"); } }
public static void GiveNumeric(NumericType numericType, float value) { Unit mUnit = UnitComponent.Instance.MyUnit; NumericComponent numericComponent = mUnit.GetComponent <NumericComponent>(); numericComponent.Set(numericType, numericComponent.GetAsFloat(numericType) + value); }
public void ActionHandle(BuffHandlerVar buffHandlerVar) { Buff_GiveRecover buff = (Buff_GiveRecover)buffHandlerVar.data; if (!buffHandlerVar.GetBufferValue(out BufferValue_TargetUnits targetUnits)) { return; } foreach (var v in targetUnits.targets) { NumericComponent numericComponent = v.GetComponent <NumericComponent>(); if (buff.hpValue > 0) { Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.HP, v.Id, buff.hpValue); } if (buff.hpPct > 0) { Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.HP, v.Id, numericComponent.GetAsFloat(NumericType.HPMax_Final) * buff.hpPct); } if (buff.mpValue > 0) { Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.MP, v.Id, buff.mpValue); } if (buff.mpPct > 0) { Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.MP, v.Id, numericComponent.GetAsFloat(NumericType.MPMax_Final) * buff.mpPct); } } }
/// <summary> /// 单目标 减伤列队 取出 循环执行 /// </summary> /// <param name="self"></param> public static void WhileTakeDamage(this AttackComponent self) { while (self.TakeDamages.Count > 0) { SkillItem skillItem = self.TakeDamages.Dequeue(); Unit myself = self.GetParent <Unit>(); if (!self.attackers.Contains(skillItem.GetComponent <ChangeType>().CastId)) { self.attackers.Add(skillItem.GetComponent <ChangeType>().CastId); } NumericComponent numSk = skillItem.GetComponent <NumericComponent>(); skillItem.Dispose(); NumericComponent numSelf = myself.GetComponent <NumericComponent>(); Random random = new Random(); int dom = random.Next(0, 99); int domhp = numSk[NumericType.Case]; if (dom < 26) { numSelf[NumericType.ValuationAdd] -= (domhp * 2); } else { numSelf[NumericType.ValuationAdd] -= domhp; } Console.WriteLine(" TakeDamage-143-Myself(" + myself.UnitType + ") : " + "-" + domhp + " / " + numSelf[NumericType.Valuation] + " /Count: " + self.TakeDamages.Count); } }
public void ActionHandle(BuffHandlerVar buffHandlerVar) { Buff_DamageByNumeric buff = (Buff_DamageByNumeric)buffHandlerVar.data; if (!buffHandlerVar.GetBufferValue(out BufferValue_TargetUnits targetUnits)) { return; } NumericComponent numericComponent = buffHandlerVar.source.GetComponent <NumericComponent>(); GameCalNumericTool.DamageData damageData = new GameCalNumericTool.DamageData(); damageData.damageType = buff.damageType; damageData.damageValue = Mathf.RoundToInt(numericComponent.GetAsInt(buff.numericType) * buff.baseCoff); if (buffHandlerVar.bufferValues.TryGetValue(typeof(BufferValue_DamageAddPct), out var damageAddPct)) { damageData.damageValue = Mathf.RoundToInt((1 + ((BufferValue_DamageAddPct)damageAddPct).damageAddPct) * damageData.damageValue); } damageData.isCritical = false; SkillEffectComponent skillEffectComponent = buffHandlerVar.source.GetComponent <SkillEffectComponent>(); var effectData = skillEffectComponent.GetEffectData(buffHandlerVar.skillId); if (effectData != null) { damageData.damageValue = Mathf.RoundToInt((1 + effectData.coefficientAddPct) * damageData.damageValue); damageData.isCritical = effectData.critical; } if (!SkillHelper.tempData.ContainsKey((buffHandlerVar.source, buff.buffSignal))) { SkillHelper.tempData[(buffHandlerVar.source, buff.buffSignal)] = new Dictionary <Type, IBufferValue>();
public void ActionHandle(BuffHandlerVar buffHandlerVar) { Buff_DOT buff = (Buff_DOT)buffHandlerVar.data; NumericComponent numericComponent = buffHandlerVar.source.GetComponent <NumericComponent>(); //这里只是计算一下DOT的伤害(快照机制),实际DOT的处理是在BuffMgr中管理的 BuffHandlerVar.cacheDatas_int[(buffHandlerVar.source.Id, buff.buffSignal)] = Mathf.RoundToInt(numericComponent.GetAsFloat(buff.numericType) * buff.baseCoff * numericComponent.GetAsFloat(NumericType.FinalDamage_AddPct));
public static void InitShellNumberic(DUnit shell) { NumericComponent numeric = shell.AddComponent <NumericComponent>(); UShellConfig config = shell.GetComponent <UShellConfigComponent>().ShellConfig; // 速度 numeric.Set(NumericType.SpeedBase, config.MoveSpeed); }
public static void InitTrapNumberic(DUnit trap) { NumericComponent numeric = trap.AddComponent <NumericComponent>(); UTrapConfig config = trap.GetComponent <UTrapConfigComponent>().TrapConfig; // 攻速 numeric.Set(NumericType.AttackSpeedBase, config.AttackSpeed); // 攻击力 numeric.Set(NumericType.HPDamageBase, config.HPDamage); }
public override void Dispose() { if (this.IsDisposed) { return; } base.Dispose(); NodeDataForHero = null; NumericComponent = null; }
public bool MeetCondition(BaseSkillData.IActiveConditionData data, Unit source) { SkillActiveCondition_CheckNumeric checkNumeric = data as SkillActiveCondition_CheckNumeric; NumericComponent numericComponent = source.GetComponent <NumericComponent>(); switch (checkNumeric.realtionType) { case NumericRealtionType.Greater: if (numericComponent.GetAsFloat(checkNumeric.numericType) > checkNumeric.aimValue) { return(true); } break; case NumericRealtionType.Less: if (numericComponent.GetAsFloat(checkNumeric.numericType) < checkNumeric.aimValue) { return(true); } break; case NumericRealtionType.Equal: if (numericComponent.GetAsFloat(checkNumeric.numericType) == checkNumeric.aimValue) { return(true); } break; case NumericRealtionType.NotEqual: if (numericComponent.GetAsFloat(checkNumeric.numericType) != checkNumeric.aimValue) { return(true); } break; case NumericRealtionType.GreaterEqual: if (numericComponent.GetAsFloat(checkNumeric.numericType) >= checkNumeric.aimValue) { return(true); } break; case NumericRealtionType.LessEqual: if (numericComponent.GetAsFloat(checkNumeric.numericType) <= checkNumeric.aimValue) { return(true); } break; } return(false); }
/// <summary> /// 发放工资 经验和金币 /// </summary> /// <param name="self"></param> public static void GetExpAndCoin(this AttackComponent self) { if (self.isSettlement) { return; } Unit selfunit = self.GetParent <Unit>(); NumericComponent numC = selfunit.GetComponent <NumericComponent>(); if (self != null) { int addexp = numC[NumericType.Level] * numC[NumericType.Level] + 1; int addcoin = numC[NumericType.Level] + 1; NumericComponent numeric = null; ///我的类型,我敌人的类型是什么呢 switch (selfunit.UnitType) { case UnitType.Player: if (self.attackers.Count > 0) { foreach (long tem in self.attackers.ToArray()) { numeric = Game.Scene.GetComponent <MonsterUnitComponent>().Get(tem).GetComponent <NumericComponent>(); numeric[NumericType.ExpAdd] += addexp; numeric[NumericType.CoinAdd] += addcoin; } self.attackers.Clear(); } Console.WriteLine(" DeathSettlement-205-type(得到经验和金币): " + numeric.GetParent <Unit>().UnitType + " addexp/exp: " + addexp + "/" + numeric[NumericType.Exp] + " addcoin/coin: " + addcoin + "/" + numeric[NumericType.Coin]); break; case UnitType.Monster: if (self.attackers.Count > 0) { foreach (long tem in self.attackers.ToArray()) { numeric = Game.Scene.GetComponent <UnitComponent>().Get(tem).GetComponent <NumericComponent>(); numeric[NumericType.ExpAdd] += addexp; numeric[NumericType.CoinAdd] += addcoin; } self.attackers.Clear(); } Console.WriteLine(" DeathSettlement-218-type(得到经验和金币): " + numeric.GetParent <Unit>().UnitType + " addexp/exp: " + addexp + "/" + numeric[NumericType.Exp] + " addcoin/coin: " + addcoin + "/" + numeric[NumericType.Coin]); break; } } self.isSettlement = true; }
/// <summary> /// 检查是否死亡 /// </summary> /// <param name="self"></param> /// <returns></returns> public static bool CheckDeath(this AttackComponent self) { NumericComponent numC = self.GetParent <Unit>().GetComponent <NumericComponent>(); if (numC[NumericType.Valuation] > 0) { self.isDeath = false; return(false); } self.isDeath = true; return(true); }
public bool MeetCondition(BaseSkillData.IActiveConditionData data, Unit source) { SkillActiveCondition_CheckHPMP cost = data as SkillActiveCondition_CheckHPMP; NumericComponent numericComponent = source.GetComponent <NumericComponent>(); if (numericComponent.GetAsFloat(NumericType.HP) > cost.costHp && numericComponent.GetAsFloat(NumericType.MP) > cost.costMp && numericComponent.GetAsFloat(NumericType.HP_RemainPct) > cost.costHpInPct && numericComponent.GetAsFloat(NumericType.MP_RemainPct) > cost.costMpInPct) { return(true); } return(false); }
public static void InitTowerNumberic(DUnit tower) { NumericComponent numeric = tower.AddComponent <NumericComponent>(); UTowerConfig config = tower.GetComponent <UTowerConfigComponent>().TowerConfig; // 最大血量 numeric.Set(NumericType.MaxHpBase, config.MaxHP); // 血量 numeric.Set(NumericType.HpBase, config.HP); // 攻速 numeric.Set(NumericType.AttackSpeedBase, config.AttackSpeed); // 血量恢复 numeric.Set(NumericType.HPRegainBase, config.HPRegain); // 攻击力 numeric.Set(NumericType.HPDamageBase, config.HPDamage); }
public void ActionHandle(BuffHandlerVar buffHandlerVar) { Buff_UpdateNumeric buff = (Buff_UpdateNumeric)buffHandlerVar.data; if (!buffHandlerVar.GetBufferValue(out BufferValue_TargetUnits bufferValue_TargetUnits)) { return; } NumericComponent numericComponent = buffHandlerVar.source.GetComponent <NumericComponent>(); if (buff.addValueByNumeric) { float value = numericComponent.GetAsFloat(buff.sourceNumeric) * buff.coefficient + buff.valueAdd; BuffHandlerVar.cacheDatas_float[(buffHandlerVar.source.Id, buff.buffSignal)] = value;
public static Unit Create(Scene currentScene, UnitInfo unitInfo) { UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>(); Unit unit = unitComponent.AddChildWithId <Unit, int>(unitInfo.UnitId, unitInfo.ConfigId); unitComponent.Add(unit); unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); unit.Forward = new Vector3(unitInfo.ForwardX, unitInfo.ForwardY, unitInfo.ForwardZ); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); for (int i = 0; i < unitInfo.Ks.Count; ++i) { numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i]); } unit.AddComponent <MoveComponent>(); if (unitInfo.MoveInfo != null) { if (unitInfo.MoveInfo.X.Count > 0) { using (ListComponent <Vector3> list = ListComponent <Vector3> .Create()) { list.Add(unit.Position); for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i) { list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i])); } unit.MoveToAsync(list).Coroutine(); } } } unit.AddComponent <ObjectWait>(); unit.AddComponent <XunLuoPathComponent>(); Game.EventSystem.Publish(unit.DomainScene(), new EventType.AfterUnitCreate() { Unit = unit }); return(unit); }
public static void InitRoleNumberic(DUnit role) { NumericComponent numeric = role.AddComponent <NumericComponent>(); URoleConfig config = role.GetComponent <URoleConfigComponent>().RoleConfig; // 最大血量 numeric.Set(NumericType.MaxHpBase, config.HP); // 血量 numeric.Set(NumericType.HpBase, config.HP); // 速度 numeric.Set(NumericType.SpeedBase, config.MoveSpeed); // 攻速 numeric.Set(NumericType.AttackSpeedBase, config.AttackSpeed); // 攻击力 numeric.Set(NumericType.HPDamageBase, config.HPDamage); // 警戒范围 numeric.Set(NumericType.AlertRadiusBase, config.AlertRadius); }
public static UnitInfo CreateUnitInfo(Unit unit) { UnitInfo unitInfo = new UnitInfo(); NumericComponent nc = unit.GetComponent <NumericComponent>(); unitInfo.UnitId = unit.Id; unitInfo.ConfigId = unit.ConfigId; unitInfo.Type = (int)unit.Type; Vector3 position = unit.Position; unitInfo.X = position.x; unitInfo.Y = position.y; unitInfo.Z = position.z; Vector3 forward = unit.Forward; unitInfo.ForwardX = forward.x; unitInfo.ForwardY = forward.y; unitInfo.ForwardZ = forward.z; MoveComponent moveComponent = unit.GetComponent <MoveComponent>(); if (moveComponent != null) { if (!moveComponent.IsArrived()) { unitInfo.MoveInfo = new MoveInfo(); for (int i = moveComponent.N; i < moveComponent.Targets.Count; ++i) { Vector3 pos = moveComponent.Targets[i]; unitInfo.MoveInfo.X.Add(pos.x); unitInfo.MoveInfo.Y.Add(pos.y); unitInfo.MoveInfo.Z.Add(pos.z); } } } foreach ((int key, long value) in nc.NumericDic) { unitInfo.Ks.Add(key); unitInfo.Vs.Add(value); } return(unitInfo); }
public static UnitInfo CreateUnitInfo(Unit unit) { UnitInfo unitInfo = new UnitInfo(); NumericComponent nc = unit.GetComponent <NumericComponent>(); unitInfo.X = unit.Position.x; unitInfo.Y = unit.Position.y; unitInfo.Z = unit.Position.z; unitInfo.UnitId = unit.Id; unitInfo.ConfigId = unit.ConfigId; foreach ((int key, long value) in nc.NumericDic) { unitInfo.Ks.Add(key); unitInfo.Vs.Add(value); } return(unitInfo); }
public static int GetBattleRoleCount(DUnit tower) { NumericComponent numeric = tower.GetComponent <NumericComponent>(); int halfHpAdd = (numeric.GetAsInt(NumericType.Hp) - numeric.GetAsInt(NumericType.HpBase)) / 2; if (halfHpAdd <= 0) { return(0); } int RoleId = tower.GetComponent <UTowerConfigComponent>().TowerConfig.RoleId; URoleConfig RoleConfig = URoleConfigCategory.Instance.Get(RoleId); if (RoleConfig == null) { return(0); } return(halfHpAdd / RoleConfig.HP); }
public static void SummonRoles(DUnit tower, long gamerid, int count, long targetid) { // 自身血量检测 NumericComponent numeric = tower.GetComponent <NumericComponent>(); int hpAdd = (numeric.GetAsInt(NumericType.Hp) - numeric.GetAsInt(NumericType.HpBase)); if (hpAdd <= 0) { return; } // 召唤数量检测 int roleConfigId = tower.GetComponent <UTowerConfigComponent>().TowerConfig.RoleId; int roleHp = URoleConfigCategory.Instance.Get(roleConfigId).HP; if (roleHp * count > hpAdd) { count = hpAdd / roleHp; } // 包装召唤ROLE DUnitInfo roleinfo = new DUnitInfo(); roleinfo.GamerId = gamerid; roleinfo.UnitId = IdGenerater.Instance.GenerateUnitId(0); roleinfo.ConfigId = roleConfigId; roleinfo.Camp = (int)(tower.GetComponent <CampComponent>().Camp); roleinfo.PX = tower.Position.x; roleinfo.PY = tower.Position.y; roleinfo.PZ = tower.Position.z; roleinfo.RX = tower.Rotation.x; roleinfo.RY = tower.Rotation.y; roleinfo.RZ = tower.Rotation.z; roleinfo.RW = tower.Rotation.w; roleinfo.Count = count; roleinfo.TargetId = targetid; roleinfo.OperationerId = gamerid; RoleFactory.Create(tower.Domain, roleinfo); }
public static void PlayerNumericInit(this NumericComponent self) { ///20190621 // 这里初始化base值,给各个数值进行赋值 // 注意,这两个语句都将触发数值改变组件,只是没有写Max的处理函数,所以会没有反应 self.Set(NumericType.Max, 9981150082); //self.Set(NumericType.ManageBase, 10); //self.Set(NumericType.MaxManageBase, 100); self.Set(NumericType.ValuationBase, 12); self.Set(NumericType.MaxValuationBase, 120); //self.Set(NumericType.MeasureBase, 10); //self.Set(NumericType.MaxMeasureBase, 100); self.Set(NumericType.CaseBase, 14); self.Set(NumericType.MaxCaseBase, 140); self.Set(NumericType.LevelBase, 1); self.Set(NumericType.ExpBase, 1); self.Set(NumericType.CoinBase, 1); self.Set(NumericType.ValuationAdd, 260); // HpAdd 数值,进行赋值 self.Set(NumericType.MaxValuationAdd, 260); // MaxHpAdd 数值,进行赋值 }
public static void GiveExp(Unit unit, int num, out float preProgress, out float currProgress, out bool lvUp) { NumericComponent numericComponent = unit.GetComponent <NumericComponent>(); if (numericComponent.GetAsInt(NumericType.Level) == numericComponent.GetAsInt(NumericType.LevelMax)) { preProgress = 1; currProgress = 1; lvUp = false; return; } Debug.LogFormat("单位{0}获得经验 {1}", unit.Id, num); int expMax = numericComponent.GetAsInt(NumericType.ExpMax); int preExp = numericComponent.GetAsInt(NumericType.Exp); preProgress = preExp / ((float)expMax); int currExp = preExp + num; lvUp = false; if (currExp >= expMax) { numericComponent.Set(NumericType.Level, numericComponent.GetAsInt(NumericType.Level) + 1); lvUp = true; Game.EventSystem.Run(EventIdType.UnitLvUp, unit.Id, numericComponent.GetAsInt(NumericType.Level)); if (numericComponent.GetAsInt(NumericType.Level) == numericComponent.GetAsInt(NumericType.LevelMax)) { currProgress = 1; return; } currExp -= expMax; ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>(); //ExpForLevelUp expConfig = configComponent.Get(typeof(ExpForLevelUp), numericComponent.GetAsInt(NumericType.等级)) as ExpForLevelUp; //expMax = expConfig.Exp; //numericComponent.Set(NumericType.经验Max, expMax); } currProgress = Mathf.Clamp01(currExp / ((float)expMax)); numericComponent.Set(NumericType.Exp, currExp); }
public void ActionHandle(BuffHandlerVar buffHandlerVar) { Buff_CostHP_MP cost = (Buff_CostHP_MP)buffHandlerVar.data; if (!buffHandlerVar.GetBufferValue(out BufferValue_TargetUnits targetUnits)) { return; } foreach (var v in targetUnits.targets) { Unit target = v; NumericComponent numericComponent = target.GetComponent <NumericComponent>(); float updateHp = -cost.costHp - cost.costHpInPct * numericComponent.GetAsFloat(NumericType.HPMax_Final); float updateMp = -cost.costMp - cost.costMpInPct * numericComponent.GetAsFloat(NumericType.MPMax_Final); if (updateHp != 0) { Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.HP, target.Id, updateHp); } if (updateMp != 0) { Game.EventSystem.Run(EventIdType.NumbericChange, NumericType.MP, target.Id, updateMp); } } }
protected override void Run(ETModel.Session session, M2C_CreateUnits message) { UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>(); foreach (UnitInfo unitInfo in message.Units) { if (unitComponent.Get(unitInfo.UnitId) != null) { continue; } UnitData unitData = new UnitData(); unitData.groupIndex = (GroupIndex)unitInfo.GroupIndex; unitData.layerMask = (UnitLayerMask)unitInfo.LayerMask; unitData.unitLayer = (UnitLayer)unitInfo.UnitLayer; unitData.unitTag = (UnitTag)unitInfo.UnitTag; Unit unit = UnitFactory.Create(unitInfo.UnitId, 1001, unitData); NumericComponent numericComponent = unit.GetComponent <NumericComponent>(); foreach (var v in unitInfo.UnitNumerics) { numericComponent.Set((NumericType)v.Type, v.Value); } BattleEventHandler.LoadAssets(unit); Vector3 postion = new Vector3(unitInfo.Position.X, unitInfo.Position.Y, unitInfo.Position.Z); unit.GameObject.transform.forward = new Vector3(unitInfo.Dir.X, unitInfo.Dir.Y, unitInfo.Dir.Z); unit.Position = postion; Dictionary <Type, IProperty> unitStateList = new Dictionary <Type, IProperty>(); P_Position property_Position = new P_Position(); property_Position.Value = postion; // 防止掉下去 unitStateList.Add(typeof(P_Position), property_Position); unit.GetComponent <UnitStateComponent>().Init(unitStateList); } }
/// 计算结果,传入的Dictionary中必须包含所有信息// public float GetData(NumericComponent comp, NumericComponent other) { ListComponent <int> priorityList = ListComponent <int> .Create(); ListComponent <FormulaNode> tempList = ListComponent <FormulaNode> .Create(); for (int i = 0; i < formulaNodeList.Count; i++) { FormulaNode node = new FormulaNode(formulaNodeList[i].Key, formulaNodeList[i].Value, formulaNodeList[i].IsSelf); tempList.Add(node); } for (int i = 0; i < tempList.Count; i++) { if (!float.TryParse(tempList[i].Value, out _)) { if (NumericType.Map.TryGetValue(tempList[i].Value, out int type)) { if (tempList[i].IsSelf) { tempList[i].Value = comp.GetAsFloat(type).ToString(); } else if (other != null) { tempList[i].Value = other.GetAsFloat(type).ToString(); } else { tempList[i].Value = "0"; Log.Error("计算伤害未传入目标"); } } } if (tempList[i].Key != 0 && !priorityList.Contains(tempList[i].Key)) { priorityList.Add(tempList[i].Key); } } priorityList.Sort(); while (priorityList.Count > 0) { int currentpri = priorityList[priorityList.Count - 1]; bool hasfind = false; do { hasfind = false; for (int i = 0; i < tempList.Count && tempList.Count >= 3; i++) { if (tempList[i].Key == currentpri && GetPriority(tempList[i].Value) != 0) { float final = GetOperactorFinal(tempList[i - 1].Value, tempList[i].Value, tempList[i + 1].Value); var newformula = new FormulaNode(tempList[i - 1].Key, final.ToString()); tempList.RemoveRange(i - 1, 3); tempList.Insert(i - 1, newformula); hasfind = true; break; } } } while (hasfind); priorityList.RemoveAt(priorityList.Count - 1); priorityList.Sort(); } if (tempList.Count == 0) { #if UNITY_EDITOR // UnityEngine.Debug.LogError("FormulaString is Error string = "+ lastFormatString); #endif return(0); } string outstring = tempList[0].Value;// + formulaNodeList.Count.ToString(); float finalnum = 0; if (!float.TryParse(outstring, out finalnum)) { #if UNITY_EDITOR // UnityEngine.Debug.Log(outstring); #endif finalnum = 0; } priorityList.Dispose(); tempList.Dispose(); return(finalnum); }
public static bool CalFinalDamage(long sourceUnitId, long destUnitId, DamageData skillDamageValue) { try { CharacterStateComponent unitState = UnitComponent.Instance.Get(destUnitId).GetComponent <CharacterStateComponent>(); if (unitState.Get(SpecialStateType.Die)) { return(false); } if (unitState.Get(SpecialStateType.Invincible)) { //TODO: 提示无敌状态 return(false); } NumericComponent sourceUnitNumericCom = UnitComponent.Instance.Get(sourceUnitId).GetComponent <NumericComponent>(); NumericComponent destUnitNumericCom = UnitComponent.Instance.Get(destUnitId).GetComponent <NumericComponent>(); int rateCharge = 0; //命中判定 float hitRate = sourceUnitNumericCom.GetAsFloat(NumericType.HitRate) - destUnitNumericCom.GetAsFloat(NumericType.DodgeRate); rateCharge = RandomHelper.RandomNumber(0, 100); if (rateCharge / 100.0f > hitRate) { Game.EventSystem.Run(EventIdType.AttackMissing, destUnitId); Log.Debug("Miss! 命中率 " + hitRate); return(false); } //暴击判定 //可能有技能提升效果 if (!skillDamageValue.isCritical) { float criticalRate = sourceUnitNumericCom.GetAsFloat(NumericType.CritRate); rateCharge = RandomHelper.RandomNumber(0, 100); if (rateCharge / 100.0f <= criticalRate) { //暴击判定通过 skillDamageValue.isCritical = true; } } if (skillDamageValue.isCritical) { skillDamageValue.damageValue = Mathf.RoundToInt(skillDamageValue.damageValue * sourceUnitNumericCom.GetAsFloat(NumericType.CritDamagePct)); } NumericType resistType = NumericType.ArmorResist; if (skillDamageValue.damageType != DamageType.Physic) { resistType = NumericType.MagicResist; } skillDamageValue.damageValue = Mathf.RoundToInt(skillDamageValue.damageValue * (100.0f / (destUnitNumericCom.GetAsInt(resistType) + 100.0f))); //预防可能要考虑什么白字红字,黑字粉字等乱七八糟的情况,所以专门用一个List DamageData[] array = new DamageData[1]; array[0] = skillDamageValue; //计算最终伤害加成,减免 for (int i = 0; i < array.Length; i++) { var damage = array[i]; float finalDamagePct = 1 + sourceUnitNumericCom.GetAsFloat(NumericType.FinalDamage_AddPct) - destUnitNumericCom.GetAsFloat(NumericType.FinalDamage_ReducePct); damage.damageValue = Mathf.RoundToInt(array[i].damageValue * finalDamagePct); //限定最小伤害0 damage.damageValue = Mathf.Clamp(array[i].damageValue, 0, int.MaxValue); array[i] = damage; } //给予伤害 Game.EventSystem.Run(EventIdType.GiveDamage, destUnitId, array); //给予吸血,吸法 float xiQu = sourceUnitNumericCom.GetAsFloat(NumericType.HP_LeechRate); if (xiQu > 0) { Game.EventSystem.Run(EventIdType.GiveHealth, sourceUnitId, Mathf.RoundToInt(skillDamageValue.damageValue * xiQu)); } xiQu = sourceUnitNumericCom.GetAsFloat(NumericType.MP_LeechRate); if (xiQu > 0) { Game.EventSystem.Run(EventIdType.GiveMp, sourceUnitId, Mathf.RoundToInt(skillDamageValue.damageValue * xiQu)); } return(true); } catch (Exception e) { Debug.LogError(e.ToString()); return(false); } }
// protected override void Run(Tank entity, C2B_AttackTankRequest message) // { // if (entity.Id != message.SourceTankId) // { // Log.Debug("客户端发送炮弹有误"); // return; // } // // B2C_AttackTankResponse sc = new B2C_AttackTankResponse(); // // Tank tank = Game.Scene.GetComponent<TankComponent>().Get(message.TargetTankId); // // tank.GetComponent<NumericComponent>().Change(NumericType.HpBase, -message.Damage); // // sc.SourceTankId = entity.Id; // // sc.TargetTankId = message.TargetTankId; // // sc.Damage = message.Damage; // // entity.BroadcastExceptSelf(sc); // } protected override async ETTask Run(Tank entity, C2B_AttackTankRequest message, Action <B2C_AttackTankResponse> reply) { Console.WriteLine($"{entity.Name} 攻击伤害 {message.Damage}"); try { if (entity.Id != message.SourceTankId) { Log.Debug("客户端发送炮弹有误"); return; } Tank targetTank = entity.Battle.Get(message.TargetTankId); if (entity.TankCamp == targetTank.TankCamp) { Console.WriteLine($"{entity.Name}攻击{targetTank.Name}无效,双方同阵营"); return; } if (targetTank.Died) { Console.WriteLine($"{entity.Name}攻击{targetTank.Name}无效,{targetTank.Name}已死亡"); return; } B2C_AttackTankResponse response = new B2C_AttackTankResponse(); NumericComponent sourceNumeric = entity.GetComponent <NumericComponent>(); NumericComponent targetNumeric = targetTank.GetComponent <NumericComponent>(); int damage = targetNumeric[NumericType.HpBase] < message.Damage ? targetNumeric[NumericType.HpBase] : message.Damage; sourceNumeric.Change(NumericType.DamageBase, damage); targetNumeric.Change(NumericType.TakeDamageBase, damage); int curtHp = targetNumeric.Change(NumericType.HpBase, -damage); if (damage != 0 && curtHp == 0) { sourceNumeric.Change(NumericType.KillsBase, +1); targetNumeric.Change(NumericType.DeathsBase, +1); } Console.WriteLine($"目标坦克{targetTank.Name} 剩余血量 {curtHp}"); response.SourceTankId = entity.Id; response.TargetTankId = message.TargetTankId; response.CurrentHp = curtHp; reply(response); await ETTask.CompletedTask; Send_B2CAttackTank(entity, response.SourceTankId, response.TargetTankId, response.CurrentHp); } catch (Exception e) { Log.Error(e); } //entity.BroadcastExceptSelf(response); }
public static void SetUnitNumericActionImp(DUnit unit, NumericType numeric, float val) { NumericComponent numericComponent = unit.GetComponent <NumericComponent>(); numericComponent.Set(numeric, val); }