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.
171 lines
5.9 KiB
171 lines
5.9 KiB
namespace ET |
|
{ |
|
[FriendClass(typeof (Gather))] |
|
[FriendClass(typeof (ResourcePoint))] |
|
public static class GatherSystem |
|
{ |
|
public static void FromMessage(this Gather self, GatherProto gatherProto) |
|
{ |
|
self.Id = gatherProto.Id; |
|
self.PeopleIdList = gatherProto.PeopleIdList; |
|
self.PreparePeopleIdList = gatherProto.PreparePeopleIdList; |
|
self.ResPointId = gatherProto.ResPointId; |
|
self.ResConfigId = gatherProto.ResConfigId; |
|
} |
|
|
|
public static GatherProto ToMessage(this Gather self) |
|
{ |
|
GatherProto proto = new GatherProto(); |
|
proto.Id = self.Id; |
|
proto.PeopleIdList = self.PeopleIdList; |
|
proto.PreparePeopleIdList = self.PreparePeopleIdList; |
|
proto.ResConfigId = self.ResConfigId; |
|
proto.ResPointId = self.ResPointId; |
|
return proto; |
|
} |
|
|
|
public static bool GoGather(this Gather self, long peopleId) |
|
{ |
|
self.PreparePeopleIdList.Add(peopleId); |
|
return true; |
|
} |
|
public static bool StartGather(this Gather self, long peopleId) |
|
{ |
|
if (self.PreparePeopleIdList.Contains(peopleId) && !self.PeopleIdList.Contains(peopleId)) |
|
{ |
|
self.PreparePeopleIdList.Remove(peopleId); |
|
self.PeopleIdList.Add(peopleId); |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
public static bool StopGather(this Gather self, long peopleId) |
|
{ |
|
bool result = self.PeopleIdList.Remove(peopleId) || self.PreparePeopleIdList.Remove(peopleId); |
|
if (self.PeopleIdList.Count == 0 && self.PreparePeopleIdList.Count == 0) |
|
{ |
|
self.Dispose(); |
|
} |
|
|
|
return result; |
|
} |
|
|
|
|
|
|
|
public static bool IsOver(this Gather self) |
|
{ |
|
return self.PreparePeopleIdList.Count == 0 && self.PeopleIdList.Count == 0; |
|
} |
|
|
|
public static bool HavePeople(this Gather self, long peopleId) |
|
{ |
|
return self.IsReadyPeople(peopleId) || self.IsGatherPeople(peopleId); |
|
} |
|
|
|
public static bool IsReadyPeople(this Gather self, long peopleId) |
|
{ |
|
foreach (var v in self.PreparePeopleIdList) |
|
{ |
|
if (v == peopleId) |
|
{ |
|
return true; |
|
} |
|
} |
|
|
|
return false; |
|
} |
|
|
|
public static bool IsGatherPeople(this Gather self, long peopleId) |
|
{ |
|
foreach (var v in self.PeopleIdList) |
|
{ |
|
if (v == peopleId) |
|
{ |
|
return true; |
|
} |
|
} |
|
|
|
return false; |
|
} |
|
|
|
#if SERVER |
|
public static ResourceAttri Product(this Gather self, Unit unit, int tick) |
|
{ |
|
self.GatherTime += tick; |
|
ResourcePoint res = unit.GetComponent<ResourcePointComponent>().GetChild<ResourcePoint>(self.ResPointId); |
|
ResourcesConfig config = ResourcesConfigCategory.Instance.Get(self.ResConfigId); |
|
int amount = 0; |
|
if (config.OutInterval == 0 && self.PeopleIdList.Count > 0) |
|
{ |
|
amount = config.OutAmount; |
|
} |
|
else |
|
{ |
|
//每次的产量 |
|
amount = GatherOperate.GetPeopleProduceAmount(unit, self.PeopleIdList, config.BaseEfficient); |
|
} |
|
|
|
//资源扣除 |
|
if (res != null) |
|
{ |
|
var (finish, product) = res.Product(config.Id, amount); |
|
if (finish) |
|
{ |
|
GatherOperate.FinishGather(unit, self.Id); |
|
MessageHelper.SendToClient(unit, new M2C_NotifyGatherFinish() { GatherId = self.Id }); |
|
} |
|
|
|
unit.GetComponent<StoreComponent>().Add(config.BaseOut, product); |
|
|
|
var rate = (float) res.ResAttriDic[config.Id].GatherAmount / (float) res.ResAttriDic[config.Id].MaxAmount; |
|
//额外产出 |
|
for (int i = 0; i < res.ResAttriDic[config.Id].ExtraOuts.Count; i++) |
|
{ |
|
var v = res.ResAttriDic[config.Id].ExtraOuts[i]; |
|
var num = (int) (rate * v.MaxAmount); |
|
if (finish) |
|
{ |
|
num = v.MaxAmount; |
|
} |
|
|
|
if (num > v.GatherAmount) |
|
{ |
|
unit.GetComponent<StoreComponent>().Add(v.CfgId, num - v.GatherAmount); |
|
res.ResAttriDic[config.Id].ExtraOuts[i] = new ExtraOut() { CfgId = v.CfgId, GatherAmount = num, MaxAmount = v.MaxAmount }; |
|
} |
|
} |
|
} |
|
|
|
//月圆之夜, |
|
if (unit.IsMoonNight()) |
|
{ |
|
// int rand = RandomHelper.RandInt32() % 100; |
|
// if (rand < config.OutProbability) |
|
// { |
|
// var dropConfig = DropGroupConfigCategory.Instance.Get(config.MoonnightOut); |
|
// int index = 0; |
|
// if (dropConfig.ItemId.Length > 1) |
|
// { |
|
// index = RandomHelper.RandomByWeight(dropConfig.Weight); |
|
// } |
|
// |
|
// //掉落数量 |
|
// int dropAmount = RandomHelper.RandomNumber(dropConfig.DropAmount[index * 2], dropConfig.DropAmount[index * 2 + 1]); |
|
// unit.GetComponent<StoreComponent>().Add(dropConfig.ItemId[index], dropAmount); |
|
// } |
|
} |
|
|
|
// //露水 |
|
// if (config.DewEachOut > 0 && unit.CanProductDew()) |
|
// { |
|
// unit.GetComponent<StoreComponent>().Add(ConstValue.DewConfigId, config.DewEachOut); |
|
// } |
|
|
|
return res.ResAttriDic[config.Id]; |
|
} |
|
|
|
#endif |
|
} |
|
} |