using System.Collections.Generic; using System.Linq; namespace ET { [FriendClass(typeof(Gather))] [FriendClass(typeof(ResourcePoint))] public static class GatherOperate { public static (int,long) GatherResource(Unit unit, long resPointId, int resConfigId,List peopleIdList,long gatherId) { ResourcePoint resource = unit.GetComponent().GetChild(resPointId); if (resource == null) { return (ErrorCode.ERR_ResourceNotFound,0); } List peopleList = new List(); foreach (var id in peopleIdList) { People people = unit.GetComponent().GetChild(id); if (people == null) { return (ErrorCode.ERR_PeopleNotFound,0); } if (resource.Config.Type==1 && people.GetPeopleType() > 1) { return (ErrorCode.ERR_PeopleTypeError, 0); } peopleList.Add(people); } if (!resource.HaveResource(resConfigId)) { return (ErrorCode.ERR_ResourceOver,0); } Gather gather = unit.GetOrAddComponent().AddChildWithNotZeroId(gatherId); gather.PreparePeopleIdList = peopleIdList; gather.ResPointId = resPointId; gather.ResConfigId = resConfigId; foreach (var people in peopleList) { PeopleOperate.StopBehave(unit, people); people.SetBehaveType(ConstBehaveType.BEHAVE_PREPARE_GATHER); people.SetTargetId(gather.Id); } return (ErrorCode.ERR_Success, gather.Id); } public static int StartGather(Unit unit, long gatherId, long peopleId) { People people = unit.GetComponent().GetChild(peopleId); if (people == null) { return ErrorCode.ERR_PeopleNotFound; } Gather gather = unit.GetComponent().GetChild(gatherId); if (gather == null) { return ErrorCode.ERR_GatherNotFound; } var behaveType = people.GetBehaveType(); if ( behaveType == ConstBehaveType.BEHAVE_PREPARE_GATHER && gather.PreparePeopleIdList.Remove(peopleId) ) { gather.PeopleIdList.Add(peopleId); people.SetBehaveType(ConstBehaveType.BEHAVE_GATHER); return ErrorCode.ERR_Success; } return ErrorCode.ERR_OperateFail; } public static int StopGather(Unit unit, long gatherId, long peopleId) { People people = unit.GetComponent().GetChild(peopleId); if (people == null) { return ErrorCode.ERR_PeopleNotFound; } Gather gather = unit.GetComponent().GetChild(gatherId); if (gather == null) { return ErrorCode.ERR_GatherNotFound; } var behaveType = people.GetBehaveType(); if ( (behaveType == ConstBehaveType.BEHAVE_PREPARE_GATHER && gather.PreparePeopleIdList.Remove(peopleId) ) ||(behaveType == ConstBehaveType.BEHAVE_GATHER && gather.PeopleIdList.Remove(peopleId)) ) { if (gather.IsOver()) { gather.Dispose(); } people.SetBehaveType(ConstBehaveType.BEHAVE_IDLE); people.SetTargetId(0); return ErrorCode.ERR_Success; } return ErrorCode.ERR_OperateFail; } public static int CancelGather(Unit unit, long gatherId) { Gather gather = unit.GetComponent().GetChild(gatherId); if (gather == null) { return ErrorCode.ERR_GatherNotFound; } List idList = gather.PeopleIdList.Union(gather.PreparePeopleIdList).ToList (); foreach (var id in idList) { People people = unit.GetComponent().GetChild(id); people.SetBehaveType(ConstBehaveType.BEHAVE_IDLE); people.SetTargetId(0); } gather.Dispose(); return ErrorCode.ERR_Success; } public static int FinishGather(Unit unit, long gatherId) { Gather gather = unit.GetComponent().GetChild(gatherId); if (gather == null) { return ErrorCode.ERR_GatherNotFound; } List idList = gather.PeopleIdList.Union(gather.PreparePeopleIdList).ToList (); foreach (var id in idList) { People people = unit.GetComponent().GetChild(id); people.SetBehaveType(ConstBehaveType.BEHAVE_IDLE); people.SetTargetId(0); } var res = unit.GetComponent().GetChild(gather.ResPointId); var config = ResourcesConfigCategory.Instance.Get(gather.ResConfigId); if (config.Eradicate == 1) { res.Dispose(); //采集完给种子 if (res.Config.SaplingItemId > 0) { unit.GetComponent().Add(res.Config.SaplingItemId,1); } } gather.Dispose(); return ErrorCode.ERR_Success; } public static int GetPeopleProduceAmount(Unit unit, List peopleIdList, int baseEfficient) { int rate = WorldParametersConfigCategory.Instance.Get(WorldParam.LaborCoefficientGather).Value[0]; int labor = 0; foreach (var peopleId in peopleIdList) { var people = unit.GetComponent().GetChild(peopleId); labor += people.GetLabor(); } //每次的产量 int amount = baseEfficient * (1 + labor / rate); return amount; } } }