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.
166 lines
6.1 KiB
166 lines
6.1 KiB
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<long> peopleIdList,long gatherId) |
|
{ |
|
ResourcePoint resource = unit.GetComponent<ResourcePointComponent>().GetChild<ResourcePoint>(resPointId); |
|
if (resource == null) |
|
{ |
|
return (ErrorCode.ERR_ResourceNotFound,0); |
|
} |
|
|
|
List<People> peopleList = new List<People>(); |
|
foreach (var id in peopleIdList) |
|
{ |
|
People people = unit.GetComponent<PeopleComponent>().GetChild<People>(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<GatherComponent>().AddChildWithNotZeroId<Gather>(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<PeopleComponent>().GetChild<People>(peopleId); |
|
if (people == null) |
|
{ |
|
return ErrorCode.ERR_PeopleNotFound; |
|
} |
|
|
|
Gather gather = unit.GetComponent<GatherComponent>().GetChild<Gather>(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, People people,Gather gather) |
|
// { |
|
// |
|
// |
|
// 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<GatherComponent>().GetChild<Gather>(gatherId); |
|
if (gather == null) |
|
{ |
|
return ErrorCode.ERR_GatherNotFound; |
|
} |
|
|
|
List<long> idList = gather.PeopleIdList.Union(gather.PreparePeopleIdList).ToList <long>(); |
|
foreach (var id in idList) |
|
{ |
|
People people = unit.GetComponent<PeopleComponent>().GetChild<People>(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<GatherComponent>().GetChild<Gather>(gatherId); |
|
if (gather == null) |
|
{ |
|
return ErrorCode.ERR_GatherNotFound; |
|
} |
|
|
|
List<long> idList = gather.PeopleIdList.Union(gather.PreparePeopleIdList).ToList <long>(); |
|
foreach (var id in idList) |
|
{ |
|
People people = unit.GetComponent<PeopleComponent>().GetChild<People>(id); |
|
people.SetBehaveType(ConstBehaveType.BEHAVE_IDLE); |
|
people.SetTargetId(0); |
|
} |
|
|
|
var res = unit.GetComponent<ResourcePointComponent>().GetChild<ResourcePoint>(gather.ResPointId); |
|
var config = ResourcesConfigCategory.Instance.Get(gather.ResConfigId); |
|
if (config.Eradicate == 1) |
|
{ |
|
res.Dispose(); |
|
//采集完给种子 |
|
if (res.Config.SaplingItemId > 0) |
|
{ |
|
unit.GetComponent<StoreComponent>().Add(res.Config.SaplingItemId,1); |
|
} |
|
} |
|
gather.Dispose(); |
|
return ErrorCode.ERR_Success; |
|
} |
|
|
|
|
|
public static int GetPeopleProduceAmount(Unit unit, List<long> peopleIdList, int baseEfficient) |
|
{ |
|
int rate = WorldParametersConfigCategory.Instance.Get(WorldParam.LaborCoefficientGather).Value[0]; |
|
int labor = 0; |
|
foreach (var peopleId in peopleIdList) |
|
{ |
|
var people = unit.GetComponent<PeopleComponent>().GetChild<People>(peopleId); |
|
labor += people.GetLabor(); |
|
} |
|
|
|
//每次的产量 |
|
int amount = baseEfficient * (1 + labor / rate); |
|
return amount; |
|
} |
|
|
|
|
|
} |
|
} |