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.
63 lines
2.2 KiB
63 lines
2.2 KiB
using System.Collections.Generic; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof (People))] |
|
[FriendClass(typeof (Gather))] |
|
public static class PeopleOperate |
|
{ |
|
public static int StopBehave(Unit unit, People people) |
|
{ |
|
var peopleBehave = people.GetBehaveType(); |
|
var targetId = people.GetTargetId(); |
|
switch (peopleBehave) |
|
{ |
|
case ConstBehaveType.BEHAVE_GATHER: |
|
case ConstBehaveType.BEHAVE_PREPARE_GATHER: |
|
var gather = unit.GetComponent<GatherComponent>().GetChild<Gather>(targetId); |
|
if (gather == null) |
|
{ |
|
return ErrorCode.ERR_GatherNotFound; |
|
} |
|
|
|
gather.StartGather(people.Id); |
|
break; |
|
case ConstBehaveType.BEHAVE_CONSTRUCT: |
|
case ConstBehaveType.BEHAVE_PREPARE_CONSTRUCT: |
|
var construct = unit.GetComponent<GatherComponent>().GetChild<Construct>(targetId); |
|
if (construct == null) |
|
{ |
|
return ErrorCode.ERR_ConstructNotFound; |
|
} |
|
construct.StopConstruct(people.Id); |
|
break; |
|
case ConstBehaveType.BEHAVE_PREPARE_CABIN: |
|
case ConstBehaveType.BEHAVE_CABIN: |
|
var canbin = unit.GetGrandChild<Cabin>(targetId); |
|
if (canbin == null) |
|
{ |
|
return ErrorCode.ERR_CabinNotFound; |
|
} |
|
canbin.PeopleLeave(); |
|
break; |
|
|
|
} |
|
|
|
people.BehaveIdle(); |
|
return ErrorCode.ERR_Success; |
|
} |
|
|
|
public static int ChangeBehave(Unit unit, People people, int behaveType, long targetId = 0) |
|
{ |
|
var result = StopBehave(unit, people); |
|
if (result != ErrorCode.ERR_Success) |
|
{ |
|
return result; |
|
} |
|
|
|
people.TargetId = targetId; |
|
people.SetBehaveType(behaveType); |
|
return ErrorCode.ERR_Success; |
|
} |
|
} |
|
} |