public Error DoPassive(ICanDo workerObject, PassiveAction action, bool visible) { if (workerObject.IsBlocked > 0) { return(Error.ObjectNotFound); } action.IsVisible = visible; SetPassiveActionParams(action); action.WorkerObject = workerObject; action.ActionId = actionIdGen.GetNext(); passive.Add(action.ActionId, action); Error ret = action.Execute(); if (ret != Error.Ok) { action.StateChange(ActionState.Failed); passive.Remove(action.ActionId); actionIdGen.Release(action.ActionId); } else { action.StateChange(ActionState.Started); } return(ret); }
public void Add(IGameObject referenceObject, PassiveAction action) { PassiveAction workingStub; if (!actionWorker.PassiveActions.TryGetValue(action.ActionId, out workingStub)) { throw new Exception("Action not found"); } var newReference = new ReferenceStub((ushort)referenceIdGen.GetNext(), referenceObject, workingStub, cityId); reference.Add(newReference); dbManager.Save(newReference); ReferenceAdded(this, new ActionReferenceArgs { ReferenceStub = newReference }); }
public void DbLoaderDoPassive(PassiveAction action) { SetPassiveActionParams(action); if (action.IsChain) { action.OnNotify -= NotifyPassive; actionIdGen.Set(action.ActionId); } else { if (action is ScheduledPassiveAction) { Schedule(action as ScheduledPassiveAction); } actionIdGen.Set(action.ActionId); passive.Add(action.ActionId, action); } }
public void DoOnce(IGameObject workerObject, PassiveAction action) { if (passive.Values.Any(a => a.Type == action.Type)) { return; } uint actionId = actionIdGen.GetNext(); action.WorkerObject = workerObject; action.ActionId = actionId; SetPassiveActionParams(action); passive.Add(action.ActionId, action); locker.Lock(LockDelegate()).Do(() => { action.Execute(); }); }
private void SetPassiveActionParams(PassiveAction action) { action.OnNotify += NotifyPassive; action.ActionIdGenerator = actionIdGen; action.Location = Location; }