public bool CanAct(WorldObject other) { bool res = other != null && !other.IsDestroyed(); if (res) { Cottage cottage = other.Owner.FindComponent <Cottage>(); LayerTile l1 = Map.map.GetTileByWorldPosition(cottage.wo.GetCenteredPosition()); LayerTile l2 = Map.map.GetTileByWorldPosition(wo.GetCenteredPosition()); res = !cottage.UnderConstruction() && cottage.GetCount() < cottage.maxOccupation && !cottage.GetPeople().Contains(wo) && wo.player == cottage.wo.player && Map.map.Adjacent(l1, l2) && (wo.GetAction() == ActionEnum.Exit || wo.GetAction() == ActionEnum.Idle); } return(res); }
public void EnterCottage(WorldObject cot) { if (CanAct(cot)) { Cottage cottage = cot.Owner.FindComponent <Cottage>(); LayerTile l1 = Map.map.GetTileByWorldPosition(cottage.wo.GetCenteredPosition()); LayerTile l2 = Map.map.GetTileByWorldPosition(wo.GetCenteredPosition()); cottage.SetCount(cottage.GetCount() + 1); nextTile = l1; currentTile = l2; this.cottage = cottage; Trace.WriteLine(cottage.GetCount()); wo.SetAction(ActionEnum.Enter); if (wo.animation != null) { wo.animation.Cancel(); } wo.animation = new WaveEngine.Components.GameActions.MoveTo2DGameAction(Owner, l1.LocalPosition, TimeSpan.FromSeconds(wo.genericSpeed)); wo.animation.Run(); } }