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.
 
 
 
 
 
 

329 lines
10 KiB

using ET.EventType;
namespace ET
{
public class PeopleAwakeSystem: AwakeSystem<People, int>
{
public override void Awake(People self, int configId)
{
self.ConfigId = configId;
}
}
[FriendClass(typeof (People))]
public static class PeopleSystem
{
public static void FromMessage(this People self, PeopleProto peopleProto)
{
self.Id = peopleProto.Id;
self.Name = peopleProto.Name;
self.ConfigId = peopleProto.ConfigId;
self.Labor = peopleProto.LaborLevel;
self.LaborExp = peopleProto.LaborExp;
self.Level = peopleProto.Level;
self.Exp = peopleProto.Exp;
self.Age = peopleProto.Age;
self.SetBehaveType(peopleProto.BehaveType);
self.TargetId = peopleProto.TargetId;
self.PosX = peopleProto.X;
self.PosY = peopleProto.Y;
if (peopleProto.SkillList.Count > 0)
{
var skillCom = self.GetOrAddComponent<SkillComponent>();
foreach (var v in peopleProto.SkillList)
{
var skill = skillCom.AddChildWithId<Skill>(v.Id);
skill.FromMessage(v);
}
}
}
public static PeopleProto ToMessage(this People self)
{
PeopleProto peopleProto = new PeopleProto();
peopleProto.Id = self.Id;
peopleProto.Name = self.Name;
peopleProto.ConfigId = self.ConfigId;
peopleProto.LaborLevel = self.Labor;
peopleProto.LaborExp = self.LaborExp;
peopleProto.Level = self.Level;
peopleProto.Exp = self.Exp;
peopleProto.Age = self.Age;
peopleProto.BehaveType = self.BehaveType;
peopleProto.TargetId = self.TargetId;
peopleProto.X = self.PosX;
peopleProto.Y = self.PosY;
var skillCom = self.GetComponent<SkillComponent>();
if (skillCom != null)
{
foreach (var v in skillCom.Children.Values)
{
var skill = (Skill) v;
peopleProto.SkillList.Add(skill.ToMessage());
}
}
return peopleProto;
}
public static int GetStrength(this People self)
{
var numericComp = self.GetComponent<NumericComponent>();
return numericComp.GetAsInt(NumericType.Strength);
}
public static int GetGender(this People self)
{
var numericComp = self.GetComponent<NumericComponent>();
return numericComp.GetAsInt(NumericType.Gender);
}
public static int GetBehaveType(this People self)
{
return self.BehaveType;
}
public static void SetBehaveType(this People self, int val)
{
self.BehaveType = val;
#if !SERVER
Game.EventSystem.Publish(new EventType.BehaveTypeChanged() { People = self });
#endif
}
public static long GetTargetId(this People self)
{
return self.TargetId;
}
public static void SetTargetId(this People self, long val)
{
self.TargetId = val;
}
public static int GetHp(this People self)
{
var nc = self.GetComponent<NumericComponent>();
return nc.GetAsInt(NumericType.HP);
}
public static bool PeopleMove(this People self, float x, float y)
{
self.PosX = x;
self.PosY = y;
return true;
}
public static int GetPeopleType(this People self)
{
return self.Config.Type;
}
public static void InitNumericComponent(this People self)
{
var nc = self.AddComponent<NumericComponent>();
nc.Set(NumericType.PeopleType, self.Config.Type);
nc.Set(NumericType.Gender, self.Config.Gender);
nc.Set(NumericType.Age, self.Age);
nc.Set(NumericType.Labor, self.Config.Labor);
nc.Set(NumericType.Wisdom, self.Config.Wisdom);
nc.Set(NumericType.MoveSpeed, self.Config.MoveSpeed);
if (self.AttriConfig != null)
{
nc.Set(NumericType.Domination, self.AttriConfig.Domination);
nc.Set(NumericType.Strength, self.AttriConfig.Strength);
nc.Set(NumericType.Endurance, self.AttriConfig.Endurance);
nc.Set(NumericType.Agile, self.AttriConfig.Agile);
nc.Set(NumericType.SpiritualPower, self.AttriConfig.SpiritualPower);
}
}
public static int GetLabor(this People self)
{
var nc = self.GetComponent<NumericComponent>();
return nc.GetAsInt(NumericType.Labor);
}
//建造相关
public static int GetLaborWithCoefficient(this People self)
{
int labor = self.GetLabor();
int laborCoefficientBuild = WorldParametersConfigCategory.Instance.Get(WorldParam.LaborCoefficientBuild).Value[0];
return labor * laborCoefficientBuild;
}
//农民类型才会成长,年龄增加
public static void GrowUp(this People self)
{
if (self.PeopleType != (int) RoleTypeEnum.VILLAGERS)
{
return;
}
self.Age += 1;
}
//返回true表示死亡
public static bool CheckPeopleDie(this People self)
{
if (self.PeopleType == (int) RoleTypeEnum.VILLAGERS && self.Age >= self.AgeMax)
{
return true;
}
return false;
}
//增加体质经验
public static void AddPhysiqueExp(this People self, int exp)
{
if (self.PeopleType != (int) RoleTypeEnum.VILLAGERS)
{
return;
}
self.PhysiqueExp += exp;
var config = PhysiqueConfigCategory.Instance.Get(self.Physique);
if (self.PhysiqueExp < 0)
{
self.PhysiqueExp = 0;
}
if (self.PhysiqueExp >= config.Exp)
{
self.Physique += 1;
self.PhysiqueExp -= config.Exp;
}
}
//增加寿命经验
public static void AddLifeExp(this People self, int exp)
{
if (self.PeopleType != (int) RoleTypeEnum.VILLAGERS)
{
return;
}
self.AgeExp += exp;
var configList = LifeExpConfigCategory.Instance.GetList();
var phyConfig = PhysiqueConfigCategory.Instance.Get(self.Physique);
int ageMax = 0;
foreach (var v in configList)
{
if (self.AgeExp < v.LifeExp)
{
ageMax = v.Life;
break;
}
}
if (ageMax > phyConfig.LifeMax)
{
ageMax = phyConfig.LifeMax;
}
self.AgeMax = ageMax;
var lifeConfig = LifeExpConfigCategory.Instance.Get(self.AgeMax);
if (self.AgeExp > lifeConfig.LifeExp)
{
self.AgeExp = lifeConfig.LifeExp;
}
}
//增加劳力经验
public static void AddLaborExp(this People self, int exp)
{
if (self.PeopleType != (int) RoleTypeEnum.VILLAGERS)
{
return;
}
self.LaborExp += exp;
var config = LaborConfigCategory.Instance.Get(self.Labor);
while (self.LaborExp > config.LaborExp)
{
var stageLabor = self.GetAgeStageLaborMax();
if (self.Labor >= stageLabor)
{
self.Labor = stageLabor;
config = LaborConfigCategory.Instance.Get(self.Labor);
if (self.LaborExp > config.LaborExp)
{
self.LaborExp = config.LaborExp;
return;
}
}
self.LaborExp -= config.LaborExp;
self.Labor++;
config = LaborConfigCategory.Instance.Get(self.Labor);
}
}
public static int GetAgeStageLaborMax(this People self)
{
var ageStageList = AgeStageConfigCategory.Instance.GetList();
foreach (var v in ageStageList)
{
if (self.Age < v.EndAge)
{
return v.LaborMax;
}
}
return 1;
}
//每分钟更新体质经验
public static void UpdatePhysiqueExp(this People self, int food)
{
var exp = (int)(-1*self.Disease/5);
if (food < 0)
{
exp += food * 40;
}
self.AddPhysiqueExp(exp);
}
//疾病影响经验
public static void UpdateLifeExp(this People self)
{
var injuryLv = 0;
var diseaseLv = 0;
int exp = 0;
var configs = DiseaseConfigCategory.Instance.GetList();
foreach (var v in configs)
{
if (v.Type == (int) (DiseaseTypeEnum.INJURY))
{
if (self.Injury > v.Min)
{
injuryLv = v.Level;
}
}
if (v.Type == (int) (DiseaseTypeEnum.ILLNESS))
{
if (self.Disease > v.Min)
{
diseaseLv = v.Level;
}
}
}
if (injuryLv > 2)
{
exp += -1 * self.Injury * 5;
}
if (diseaseLv > 2)
{
exp += -1 * self.Disease * 5;
}
self.AddLifeExp(exp);
}
}
}