You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
481 lines
15 KiB
481 lines
15 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using ET.EventType; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(Fighter))] |
|
[FriendClass(typeof(People))] |
|
[FriendClass(typeof(NumericComponent))] |
|
[FriendClass(typeof(Modifier))] |
|
[FriendClass(typeof(Buff))] |
|
[FriendClass(typeof(Skill))] |
|
public static class FighterSystem |
|
{ |
|
public static void FromPeople(this Fighter self, People people) |
|
{ |
|
self.Name = people.Name; |
|
self.ConfigId = people.ConfigId; |
|
self.IsAlive = true; |
|
//self.AtkId = self.AttriConfig.NormalAttack; |
|
|
|
NumericComponent numericComponent = people.GetComponent<NumericComponent>(); |
|
if (numericComponent != null) |
|
{ |
|
NumericComponent nc = self.AddComponent<NumericComponent>(); |
|
foreach (var v in numericComponent.NumericDic.Keys) |
|
{ |
|
nc.InitNumericValue(v, numericComponent.NumericDic[v]); |
|
} |
|
|
|
//初始化战意 |
|
// nc.InitNumericValue(NumericType.FightingSpirit, 0); |
|
} |
|
|
|
var skillCom = people.GetComponent<SkillComponent>(); |
|
if (skillCom != null) |
|
{ |
|
var fSkillCom = self.GetOrAddComponent<SkillComponent>(); |
|
foreach (var v in skillCom.Children.Values) |
|
{ |
|
var skill = fSkillCom.AddChildWithId<Skill>(v.Id); |
|
skill.CloneSkill((Skill) v); |
|
} |
|
} |
|
} |
|
|
|
public static void FromMonster(this Fighter self, MonsterConfig config) |
|
{ |
|
self.Name = config.Name; |
|
self.IsAlive = true; |
|
self.ConfigId = config.Id; |
|
NumericComponent nc = self.AddComponent<NumericComponent>(); |
|
// nc.InitNumericValue(NumericType.ATK, config.ATK); |
|
nc.InitNumericValue(NumericType.Lv, config.LV); |
|
nc.InitNumericValue(NumericType.HP, config.HP); |
|
nc.InitNumericValue(NumericType.HpMax, config.HP); |
|
nc.InitNumericValue(NumericType.DEF, config.DEF); |
|
nc.InitNumericValue(NumericType.AttackSpeed, config.AttackSpeed); |
|
nc.InitNumericValue(NumericType.HitRate, config.HitRate); |
|
nc.InitNumericValue(NumericType.ParryRate, config.ParryRate); |
|
nc.InitNumericValue(NumericType.DodgeRate, config.DodgeRate); |
|
nc.InitNumericValue(NumericType.MoveSpeed, config.MoveSpeed); |
|
self.AtkId = config.NormalAttack; |
|
self.FightType = ConstFightType.FIGHT_TYPE_MONSTER; |
|
} |
|
|
|
public static FighterProto ToMessage(this Fighter self) |
|
{ |
|
var proto = new FighterProto(); |
|
proto.Id = self.Id; |
|
proto.Name = self.Name; |
|
proto.IsAlive = true; |
|
proto.ConfigId = self.ConfigId; |
|
proto.Pos = self.Pos; |
|
proto.AtkId = self.AtkId; |
|
proto.FightType = self.FightType; |
|
var nc = self.GetComponent<NumericComponent>(); |
|
if (null != nc) |
|
{ |
|
foreach (var v in nc.NumericDic) |
|
{ |
|
proto.Ks.Add(v.Key); |
|
proto.Vs.Add(v.Value); |
|
} |
|
} |
|
|
|
var skillcom = self.GetComponent<SkillComponent>(); |
|
if (skillcom != null) |
|
{ |
|
foreach (var skill in skillcom.Children.Values) |
|
{ |
|
proto.SkillList.Add(((Skill) skill).ToMessage()); |
|
} |
|
} |
|
|
|
return proto; |
|
} |
|
|
|
public static void FromMessage(this Fighter self, FighterProto fighterProto) |
|
{ |
|
self.Name = fighterProto.Name; |
|
self.IsAlive = fighterProto.IsAlive; |
|
self.ConfigId = fighterProto.ConfigId; |
|
self.Pos = fighterProto.Pos; |
|
self.AtkId = fighterProto.AtkId; |
|
self.FightType = fighterProto.FightType; |
|
var nc = self.GetOrAddComponent<NumericComponent>(); |
|
for (int i = 0; i < fighterProto.Ks.Count; i++) |
|
{ |
|
nc.InitNumericValue(fighterProto.Ks[i], fighterProto.Vs[i]); |
|
} |
|
|
|
var skillcom = self.GetOrAddComponent<SkillComponent>(); |
|
foreach (var skillProto in fighterProto.SkillList) |
|
{ |
|
var skill = skillcom.AddChild<Skill>(); |
|
skill.FromMessage(skillProto); |
|
} |
|
} |
|
|
|
public static ProtoObject GetConfig(this Fighter self) |
|
{ |
|
if (self.FightType == ConstFightType.FIGHT_TYPE_PLAYER) |
|
{ |
|
return self.Config; |
|
} |
|
|
|
return self.MonsterConfig; |
|
} |
|
|
|
public static void UpdateAtkSpeed(this Fighter self) |
|
{ |
|
self.AtkSpeed = self.GetAtkSpeed(); |
|
} |
|
|
|
public static int CanUseSkill(this Fighter self, Skill skill) |
|
{ |
|
var skillConfig = skill.Config; |
|
if (skill != null) |
|
{ |
|
//如果被沉默 |
|
if (skillConfig.Silence == (int) SkillFatherSilenceEnum.YES && self.IsSilence()) |
|
{ |
|
return ErrorCode.ERR_FighterSilence; |
|
} |
|
|
|
//如果被禁锢 |
|
if (skillConfig.GetClose == (int) SkillFatherGetCloseEnum.YES && self.IsConstraint()) |
|
{ |
|
return ErrorCode.ERR_FighterConstraint; |
|
} |
|
|
|
//如果需要消耗战意 |
|
if (skillConfig.FightingSpiritConsume > self.GetFightSpirit()) |
|
{ |
|
return ErrorCode.ERR_SkillSpiritNoEnongh; |
|
} |
|
|
|
if (skill.CoolTime > 0) |
|
{ |
|
return ErrorCode.ERR_SkillNotCd; |
|
} |
|
|
|
return ErrorCode.ERR_Success; |
|
} |
|
|
|
return ErrorCode.ERR_SkillNotFound; |
|
} |
|
|
|
public static int UseSkill(this Fighter self, Skill skill) |
|
{ |
|
var canUseSkill = self.CanUseSkill(skill); |
|
if (canUseSkill == ErrorCode.ERR_Success) |
|
{ |
|
skill.ResetCd(); |
|
self.AddFightSpirit(-1 * skill.Config.FightingSpiritConsume); |
|
} |
|
|
|
return canUseSkill; |
|
} |
|
|
|
public static bool CanAtk(this Fighter self) |
|
{ |
|
return true; |
|
} |
|
|
|
public static int Atk(this Fighter self) |
|
{ |
|
return (int) (self.GetAtk() * self.GetCritVal()); |
|
} |
|
|
|
public static int GetAtk(this Fighter self) |
|
{ |
|
int atk = 0; |
|
NumericComponent nc = self.GetComponent<NumericComponent>(); |
|
if (nc == null) |
|
{ |
|
return 0; |
|
} |
|
|
|
if (self.FightType == ConstFightType.FIGHT_TYPE_MONSTER) |
|
{ |
|
// atk = nc.GetAsInt(NumericType.ATK); |
|
} |
|
else |
|
{ |
|
// atk = nc.GetAsInt(NumericType.Strength) * 5; |
|
} |
|
|
|
return atk; |
|
} |
|
|
|
public static void InitHp(this Fighter self) |
|
{ |
|
NumericComponent nc = self.GetComponent<NumericComponent>(); |
|
// nc.InitNumericValue(NumericType.HP, nc.GetAsInt(NumericType.Endurance) * 10); |
|
// nc.InitNumericValue(NumericType.HpMax, nc.GetAsInt(NumericType.Endurance) * 10); |
|
} |
|
|
|
public static int GetHp(this Fighter self) |
|
{ |
|
NumericComponent nc = self.GetComponent<NumericComponent>(); |
|
return nc.GetAsInt(NumericType.HP); |
|
} |
|
|
|
public static int GetHpMax(this Fighter self) |
|
{ |
|
var nc = self.GetComponent<NumericComponent>(); |
|
return nc.GetAsInt(NumericType.HpMax); |
|
} |
|
|
|
public static int GetDef(this Fighter self) |
|
{ |
|
var baseDef = self.GetEndurance() / 3; |
|
List<Modifier> modifierList = null; |
|
if (self.ModifierDic.TryGetValue((int) SkillEffectEffectConfigEnum.ARMOR, out modifierList)) |
|
{ |
|
foreach (var v in modifierList) |
|
{ |
|
baseDef += v.Value; |
|
} |
|
} |
|
|
|
return baseDef; |
|
} |
|
|
|
public static int GetEndurance(this Fighter self) |
|
{ |
|
|
|
|
|
return 0; |
|
} |
|
|
|
public static int GetAtkSpeed(this Fighter self) |
|
{ |
|
NumericComponent nc = self.GetComponent<NumericComponent>(); |
|
if (nc != null) |
|
{ |
|
if (self.FightType == ConstFightType.FIGHT_TYPE_MONSTER) |
|
{ |
|
return nc.GetAsInt(NumericType.AttackSpeed); |
|
} |
|
|
|
return nc.GetAsInt(NumericType.Age) * 5; |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
//命中 |
|
public static int GetHit(this Fighter self) |
|
{ |
|
NumericComponent nc = self.GetComponent<NumericComponent>(); |
|
var hitLv = 50 + nc.GetAsInt(NumericType.Agile) * 2; |
|
var hitValue = Math.Min(hitLv * 100 / 40, 50); |
|
|
|
return hitValue; |
|
} |
|
|
|
//闪避 |
|
public static int GetDodge(this Fighter self) |
|
{ |
|
NumericComponent nc = self.GetComponent<NumericComponent>(); |
|
if (nc == null) |
|
{ |
|
return 0; |
|
} |
|
|
|
var dogeLv = nc.GetAsInt(NumericType.Agile) * 2; |
|
return Math.Min(dogeLv * 100 / 40, 50); |
|
} |
|
|
|
//暴击率 |
|
public static int GetCritRate(this Fighter self) |
|
{ |
|
NumericComponent nc = self.GetComponent<NumericComponent>(); |
|
if (nc == null) |
|
{ |
|
return 0; |
|
} |
|
|
|
var crit = nc.GetAsInt(NumericType.Agile); |
|
return Math.Min(crit * 2, 50); |
|
} |
|
|
|
//暴击值 |
|
public static float GetCritVal(this Fighter self) |
|
{ |
|
var critRate = self.GetCritRate(); |
|
var randomVal = self.GetParent<Battle>().GetRandomInt(); |
|
if (randomVal < critRate) |
|
{ |
|
return (float) 1.5; |
|
} |
|
else |
|
{ |
|
return (float) 1.0; |
|
} |
|
} |
|
|
|
//招架,这个是算招架后的伤害 |
|
public static (int, float) GetParry(this Fighter self) |
|
{ |
|
NumericComponent nc = self.GetComponent<NumericComponent>(); |
|
var parryLv = 0; |
|
var parryRate = Math.Min(parryLv * 2, 50); |
|
var randomVal = self.GetParent<Battle>().GetRandomInt(); |
|
if (randomVal < parryRate) |
|
{ |
|
return (ConstHurtType.HURT_PARRY, (float) 0.5); |
|
} |
|
|
|
return (ConstHurtType.HURT_NORMAL, 1); |
|
} |
|
|
|
public static void AddFightSpirit(this Fighter self, int val) |
|
{ |
|
if (val == 0) |
|
{ |
|
return; |
|
} |
|
|
|
NumericComponent nc = self.GetComponent<NumericComponent>(); |
|
var spirit = 0; |
|
nc.Set(0, spirit + val); |
|
} |
|
|
|
//获取战意 |
|
public static int GetFightSpirit(this Fighter self) |
|
{ |
|
//NumericComponent nc = self.GetComponent<NumericComponent>(); |
|
//return nc.GetAsInt(NumericType.FightingSpirit); |
|
return 0; |
|
} |
|
|
|
//刷新回合 |
|
public static void OnTriggerContinue(this Fighter self, int continueType) |
|
{ |
|
var buffCom = self.GetComponent<BuffComponent>(); |
|
if (buffCom == null) |
|
{ |
|
return; |
|
} |
|
|
|
foreach (var v in buffCom.Children.Values) |
|
{ |
|
var buff = (Buff) v; |
|
if (buff.Config.ContinuedType == continueType) |
|
{ |
|
buff.Duration -= 1; |
|
if (buff.Duration <= 0) |
|
{ |
|
//清理该buff的modifier |
|
foreach (var v2 in buff.Children.Values) |
|
{ |
|
var modifier = (Modifier) v2; |
|
self.ModifierDic[modifier.Config.EffectConfig].Remove(((Modifier) modifier)); |
|
} |
|
|
|
buff.Dispose(); |
|
} |
|
} |
|
} |
|
} |
|
|
|
public static void OnModifierChange(this Fighter self, int effectType) |
|
{ |
|
switch ((SkillEffectEffectConfigEnum) effectType) |
|
{ |
|
case SkillEffectEffectConfigEnum.ARMOR: //防御类型 |
|
self.UpdateNumberic(effectType, NumericType.DEF); |
|
break; |
|
case SkillEffectEffectConfigEnum.ATK: //攻击力 |
|
//self.UpdateNumberic(effectType, NumericType.ATK); |
|
break; |
|
} |
|
} |
|
|
|
public static void UpdateNumberic(this Fighter self, int effectType, int numbericType) |
|
{ |
|
int add = 0; |
|
foreach (var v in self.ModifierDic[effectType]) |
|
{ |
|
add += v.Value; |
|
} |
|
|
|
var basIndex = ServerUtil.GetBasNumIndex(numbericType); |
|
var bas = self.GetComponent<NumericComponent>().GetAsInt(basIndex); |
|
self.GetComponent<NumericComponent>().InitNumericValue(numbericType, bas + add); |
|
} |
|
|
|
//是否禁锢 |
|
public static bool IsConstraint(this Fighter self) |
|
{ |
|
if (self.HaveEffect(SkillEffectEffectConfigEnum.CONSTRAINT) || |
|
self.HaveEffect(SkillEffectEffectConfigEnum.FROZEN) || |
|
self.HaveEffect(SkillEffectEffectConfigEnum.STUPOR) |
|
) |
|
{ |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
//是否沉默 |
|
public static bool IsSilence(this Fighter self) |
|
{ |
|
if (self.HaveEffect(SkillEffectEffectConfigEnum.SILENCE) || |
|
self.HaveEffect(SkillEffectEffectConfigEnum.FROZEN) || |
|
self.HaveEffect(SkillEffectEffectConfigEnum.STUPOR)) |
|
{ |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
public static bool HaveEffect(this Fighter self, SkillEffectEffectConfigEnum effectConfigEnum) |
|
{ |
|
return self.ModifierDic.Keys.Contains((int) effectConfigEnum) && self.ModifierDic[(int) effectConfigEnum].Count > 0; |
|
} |
|
|
|
//普通攻击响应事件 |
|
public static void OnTurnEvent(this Fighter self) |
|
{ |
|
//技能CD |
|
var skillcom = self.GetComponent<SkillComponent>(); |
|
if (skillcom != null) |
|
{ |
|
foreach (var v in skillcom.Children.Values) |
|
{ |
|
var skill = (Skill) v; |
|
if (skill.Config.CDType == 2) //普通攻击CD |
|
{ |
|
skill.CdOneTime(); |
|
} |
|
} |
|
} |
|
} |
|
|
|
//回合事件 |
|
public static void OnRoundEvent(this Fighter self) |
|
{ |
|
} |
|
|
|
public static void RecoverSpirit(this Fighter self) |
|
{ |
|
// var nc = self.GetComponent<NumericComponent>(); |
|
// int sprit = nc.GetAsInt(NumericType.FightingSpirit); |
|
// sprit += 2; |
|
// if (sprit > 100) |
|
// { |
|
// sprit = 100; |
|
// } |
|
// |
|
// nc.Set(NumericType.FightingSpirit, sprit); |
|
} |
|
} |
|
} |