public void Test_LightInjuriesHealOverTime() { var you = YouInARoom(out IWorld world); var room = you.CurrentLocation; var a = new You("You", room); //give them an injury var injury = new Injured("Bruised Shin", a, 10, InjuryRegion.Leg, world.InjurySystems.First(i => i.IsDefault)); a.Adjectives.Add(injury); for (int i = 0; i < 11; i++) { var stack = new ActionStack(); stack.RunStack(world, GetUI(typeof(object)), new DoNothingAction(you), a, a.GetFinalBehaviours()); //after 9 round you should still be injured if (i < 10) { Assert.Contains(injury, a.Adjectives.ToArray(), $"unexpected injury healing on round {i}"); } else { //on 10th round it should be gone Assert.IsFalse(a.Adjectives.Contains(injury)); } } }
public void Test_HeavyInjuriesGetWorseOverTime(bool isTough, bool roomIsStale) { var you = YouInARoom(out IWorld world); var room = you.CurrentLocation; if (roomIsStale) { room.Adjectives.Add(world.AdjectiveFactory.Create(world, room, "Stale")); } //give them an injury var injury = new Injured("Cut Lip", you, 2, InjuryRegion.Leg, world.InjurySystems.First(i => i.IsDefault)); you.Adjectives.Add(injury); if (isTough) { you.Adjectives.Add(world.AdjectiveFactory.Create(world, you, "Tough")); } for (int i = 0; i < 10; i++) { var stack = new ActionStack(); stack.RunStack(world, GetUI(typeof(object)), new DoNothingAction(you), you, you.GetFinalBehaviours()); //after 2 rounds (0 and 1) you should still be injured if (i == 0) { StringAssert.AreEqualIgnoringCase("Cut Lip", injury.Name); } if (i == 21) { if (isTough && !roomIsStale) { //never gets worse Assert.AreEqual(2, injury.Severity); } else if (!roomIsStale || isTough) { //normal rate or tough in stale room //From 2 it gets worse on the following rounds //4+6+8 StringAssert.AreEqualIgnoringCase("Infected Cut Lip", injury.Name); Assert.AreEqual(5, injury.Severity); } else { //stale room and not tough //From 2 it gets worse on the following rounds //2+3+4+5+6 StringAssert.AreEqualIgnoringCase("Infected Cut Lip", injury.Name); Assert.AreEqual(7, injury.Severity); } } } }
public void Test_HealingAnInjury() { var you = YouInARoom(out IWorld world); //you cannot heal yet Assert.IsFalse(you.GetFinalActions().OfType <HealAction>().Any()); //you are a medic var medic = new Adjective(you) { Name = "Medic" }; medic.BaseActions.Add(new HealAction(you)); you.Adjectives.Add(medic); //now you can heal stuff Assert.IsTrue(you.GetFinalActions().OfType <HealAction>().Any()); //give them an injury var injury = new Injured("Cut Lip", you, 2, InjuryRegion.Leg, world.InjurySystems.First(i => i.IsDefault)); you.Adjectives.Add(injury); var stack = new ActionStack(); you.BaseStats["Savvy"] = 20; Assert.Contains(injury, you.Adjectives.ToArray()); stack.RunStack(world, new FixedChoiceUI(you, injury), you.GetFinalActions().OfType <HealAction>().Single(), you, you.GetFinalBehaviours()); Assert.IsFalse(you.Adjectives.Contains(injury)); }
protected override void PopImpl(IWorld world, IUserinterface ui, ActionStack stack, Frame frame) { var f = (EquipmentFrame)frame; switch (f.ToPerform) { case EquipmentActionToPerform.None: break; case EquipmentActionToPerform.PutOn: if (f.PerformedBy.CanEquip(f.Item, out string reason)) { f.Item.IsEquipped = true; } else { ShowNarrative(ui, f.PerformedBy, "Equip failed", $"You struggle to equip {f.Item} but find it just won't fit ({reason})", null, stack.Round); } break; case EquipmentActionToPerform.TakeOff: f.Item.IsEquipped = false; break; default: throw new ArgumentOutOfRangeException(); } }
public override void Do(ActionStack pActionStack) { base.Do(pActionStack); mActionStack = pActionStack; mOldIndex = pActionStack.EnemyAttackIndex; pActionStack.EnemyAttackIndex = mNewIndex; }
public override void Push(IWorld world, IUserinterface ui, ActionStack stack, IActor actor) { stack.Push(new Frame(actor, this, GetAttitude(actor, Owner) ?? Attitude) { TargetIfAny = Owner }); }
internal Transaction(string name, ActionStack actionStack) { Name = name; this.actionStack = actionStack; actions = new List <IUndoAction>(); status = TransactionStatus.Unkown; }
public override void OnPop(IWorld world, IUserinterface ui, ActionStack stack, Frame frame) { base.OnPop(world, ui, stack, frame); if (!(frame.TargetIfAny is IActor)) { return; } //if the target is me then I might get angry if (frame.TargetIfAny == Owner) { IDoCare(world, ui, frame, stack, frame.Attitude); } else { //is the target one of my friends? double howMuchICare = world.Relationships.Where(r => r.AppliesTo((IActor)Owner, (IActor)frame.TargetIfAny)) .Sum(r => r.Attitude); //Your hurting one of my friends, im unhappy if (howMuchICare > 0.0001) { IDoCare(world, ui, frame, stack, frame.Attitude); } //your hurting my enemies, I'm happy! if (howMuchICare < 0.001) { IDoCare(world, ui, frame, stack, -0.5 * frame.Attitude); } } }
public void TestForbidDirection() { TwoInARoom(out You you, out IActor them, out IWorld w); them.BaseBehaviours.Add(new ForbidBehaviour <LeaveAction>(new ConditionCode("return Frame.LeaveDirection == Direction.South"), them)); var behaviour = them.GetFinalBehaviours().OfType <ForbidBehaviour <LeaveAction> >().Single(); var stackA = new ActionStack(); var frameArgsA = new ActionFrameSystemArgs(you, w, null, stackA, new LeaveFrame(them, new LeaveAction(you), Direction.North, 0)); //we don't forbid going north Assert.IsFalse(behaviour.Condition.IsMet(w, frameArgsA)); var stackB = new ActionStack(); var frameArgsB = new ActionFrameSystemArgs(you, w, null, stackB, new LeaveFrame(them, new LeaveAction(you), Direction.South, 0)); //we DO forbid going South Assert.IsTrue(behaviour.Condition.IsMet(w, frameArgsB)); var ui = GetUI(Direction.South); w.RunRound(ui, new LeaveAction(you)); Assert.Contains("Chaos Sam prevented Test Wanderer from performing action Leave", ui.MessagesShown); }
void SaveActions(SaveData data) { foreach (var action in ActionStack.ToArray().Reverse()) { data.actionDatas.Add(new ActionSaveData(action)); } }
/// <summary> Helper method for <see cref="PerformStepByStep"/>. </summary> private void PerformSingleIteration(IReadOnlyList <Func <UndoableAction> > actions, int count, bool withMerge) { Console.WriteLine("Performing {0} actions", count); var policy = new FakeMergePolicy(withMerge); var undoStack = new ActionStack(Context, policy); var documentStates = new Stack <DocumentOwner>(); for (int i = 0; i < count; i++) { int originalCount = undoStack.UndoStackSize; documentStates.Push(Document.Clone()); undoStack.Do(actions[i].Invoke()); if (originalCount == undoStack.UndoStackSize) { // the document state shouldn't have been added as a merge occurred. Thus it's like this last // action was never applied in the first place documentStates.Pop(); } } while (documentStates.Count > 0) { // after each undo, we should be back to where we originally were var originalState = documentStates.Pop(); undoStack.Undo(); CheckEqual(originalState, Document); } }
public void Test_GiveItem() { var you = YouInARoom(out IWorld world); var them = new Npc("Mort", you.CurrentLocation); them.BaseActions.Clear(); Assert.IsFalse(new GiveAction(you).HasTargets(you)); var grenade = new Item("Grenade"); you.Items.Add(grenade); grenade.BaseActions.Clear(); Assert.IsTrue(new GiveAction(grenade).HasTargets(you)); var stack = new ActionStack(); //when you chose to give them the grenade stack.RunStack(world, GetUI(them), you.GetFinalActions().OfType <GiveAction>().Single(), you, null); Assert.IsFalse(you.Items.Contains(grenade)); Assert.Contains(grenade, them.Items.ToArray()); }
public override void OnPush(IWorld world, IUserinterface ui, ActionStack stack, Frame frame) { base.OnPush(world, ui, stack, frame); var coerceFrame = Coerced.CoercedFrame; //if the coerced frame has had all it's decisions made and is about to be pushed onto the stack if (ReferenceEquals(frame.Action, coerceFrame.CoerceAction)) { var args = new NegotiationSystemArgs(world, ui, coerceFrame.PerformedBy.GetFinalStats()[Stat.Coerce], coerceFrame.PerformedBy, coerceFrame.TargetIfAny, stack.Round); //the final frame that is being pushed is what we are proposing they do args.Proposed = frame; //Check with the negotiation system to see if the actor is still willing to go ahead //with the action as configured Coerced.CoercedFrame.NegotiationSystem.Apply(args); //if not then cancel if (!args.Willing) { var narrative = new Narrative(coerceFrame.PerformedBy, "Coerce Failed", $"{coerceFrame.TargetIfAny} refused to perform action", $"{coerceFrame.PerformedBy} failed to coerce {coerceFrame.TargetIfAny} - {args.WillingReason}", stack.Round); narrative.Show(ui); frame.Cancelled = true; } } }
//Generate a map and display it. Could just as easily pass it into public MapConsole(int width, int height, int viewportWidth, int viewportHeight) : base(width, height) { Map = GenerateDungeon(100, 100); GameFrameManager = new GameFrameManager(Map); GameFrameManager.LogicFrameCompleted += OnLogicCompleted; Actions = new ActionStack(); ViewPort = new XnaRect(0, 0, viewportWidth, viewportHeight); Map.ConfigureAsRenderer(this); Map.ControlledGameObject = Game.Player; Map.ControlledGameObject.IsFocused = true; // Set player to receive input, since in this example the player handles movement // Game.Player.IsFocused = true; // Set up to recalculate FOV and set camera position appropriately when the player moves. Also make sure we hook the new // Player if that object is reassigned. // Map.ControlledGameObject.Moved += Player_Moved; // Map.ControlledGameObjectChanged += ControlledGameObjectChanged; // Calculate initial FOV and center camera Map.CalculateFOV(Game.Player.Position, Game.Player.FOVRadius, Radius.CIRCLE); this.CenterViewPortOnPoint(Game.Player.Position); this.AddObserver(OnPlayerPerformedAction, InputManager.PlayerDidMoveNotification); }
protected override void PopImpl(IWorld world, IUserinterface ui, ActionStack stack, Frame frame) { _toForbid.Cancelled = true; ui.Log.Info(new LogEntry( $"{frame.PerformedBy} prevented {_toForbid.PerformedBy} from performing action {_toForbid.Action.Name}", stack.Round, _toForbid.PerformedBy)); }
public override void Push(IWorld world, IUserinterface ui, ActionStack stack, IActor actor) { if (Owner != null) { ui.ShowStats(Owner); } }
protected override void PopImpl(IWorld world1, IUserinterface ui, ActionStack stack, Frame frame) { var f = (DialogueFrame)frame; var world = frame.PerformedBy.CurrentLocation.World; //apply the dialogue system world.Dialogue.Apply(new SystemArgs(world, ui, 0, f.PerformedBy, f.DialogueTarget, stack.Round)); }
public override void Push(IWorld world, IUserinterface ui, ActionStack stack, IActor actor) { //ask actor to pick a direction if (actor.Decide <Direction>(ui, "LeaveAction Direction", null, out var direction, GetLeaveDirections(actor), 0)) { stack.Push(new LeaveFrame(actor, this, direction, 0)); } }
internal void RegisterAction(string displayName, ModelNodePath nodePath, string observableNodePath, object index, IReadOnlyCollection <IDirtiableViewModel> dirtiables, object newValue, object previousValue) { singleNodeActionRegistered = true; var actionItem = new ValueChangedActionItem(displayName, observableViewModelService, nodePath, observableNodePath, Identifier, index, dirtiables, modelContainer, previousValue); ActionStack.Add(actionItem); NotifyNodeChanged(observableNodePath); }
/// <summary> /// Override to your action once it is confirmed /// </summary> /// <param name="world"></param> /// <param name="ui"></param> /// <param name="stack"></param> /// <param name="frame"></param> public virtual void Pop(IWorld world, IUserinterface ui, ActionStack stack, Frame frame) { foreach (var e in Effect) { e.Apply(new ActionFrameSystemArgs(this, world, ui, stack, frame)); } PopImpl(world, ui, stack, frame); }
protected override void PopImpl(IWorld world, IUserinterface ui, ActionStack stack, Frame frame) { var f = (HealFrame)frame; if (f.TargetIfAny.Adjectives.Contains(f.Injury)) { f.Injury.Heal(ui, stack.Round); } }
public IScriptItem ApplyStacks(IScriptItem item) { if (item is Defrule defrule) { defrule.Conditions.AddRange(ConditionStack.Select(x => x.Copy())); defrule.Actions.AddRange(ActionStack.Select(x => x.Copy())); } return(item); }
public static void InitGame(params Type[] exceptions) { Screen.sleepTimeout = SleepTimeout.NeverSleep; ActionStack.Clear(); Crops.Clear(); foreach (var enemykvp in Enemies) { enemykvp.Value.RemoveAll(x => !x || !x.gameObject); } EnemyInfos.Clear(); var enemies = Resources.LoadAll <EnemyInformation>("Configuration"); foreach (var e in enemies) { EnemyInfos.Add(e.ID, e); } Items.Clear(); var items = Resources.LoadAll <ItemBase>("Configuration"); foreach (var i in items) { Items.Add(i.ID, i); } TalkerInfos.Clear(); var talkers = Resources.LoadAll <TalkerInformation>("Configuration"); foreach (var t in talkers) { TalkerInfos.Add(t.ID, t); } if (exceptions == null || !exceptions.Contains(typeof(TriggerHolder))) { foreach (var tholder in FindObjectsOfType <TriggerHolder>()) { tholder.Init(); } } PlayerManager.Instance.Init(); DialogueManager.Instance.Init(); if (!UIManager.Instance || !UIManager.Instance.gameObject) { Instantiate(Instance.UIPrefab); } UIManager.Instance.Init(); FieldManager.Instance.Init(); QuestManager.Instance.Init(); MessageManager.Instance.Init(); MapManager.Instance.Init(); MapManager.Instance.SetPlayer(PlayerManager.Instance.PlayerTransform); MapManager.Instance.RemakeCamera(); GatherManager.Instance.Init(); WindowsManager.Clear(); }
public override async Task Invoke(object parameter) { ActionStack?.BeginTransaction(); commands.First().NodeCommand.StartCombinedInvoke(); await Task.WhenAll(commands.Select(x => x.Invoke(parameter))); commands.First().NodeCommand.EndCombinedInvoke(); ActionStack?.EndTransaction($"Executed {Name}"); }
public override void Push(IWorld world, IUserinterface ui, ActionStack stack, IActor actor) { var chosen = PrimeWithTarget; if (chosen != null || actor.Decide(ui, "Pick Up", null, out chosen, GetTargets(actor).Cast <IItem>().ToArray(), 0)) { stack.Push(new PickUpFrame(actor, this, chosen, actor.CurrentLocation, 0)); } }
public override void Push(IWorld world, IUserinterface ui, ActionStack stack, IActor actor) { if (Owner is IItem toGive || actor.Decide(ui, "Give", "Select an item to give", out toGive, GetTargets(actor).Cast <IItem>().ToArray(), -10)) { if (actor.Decide(ui, "To whom", $"Select who to give {toGive}", out IActor toGiveTo, actor.GetCurrentLocationSiblings(false), 10)) { stack.Push(new GiveFrame(actor, this, toGive, toGiveTo, GetItemWorthInAttitude(actor, toGive, toGiveTo))); } } }
protected override void PopImpl(IWorld world, IUserinterface ui, ActionStack stack, Frame frame) { var f = frame; //if we still have the item we should drop it if (f.PerformedBy.Items.Contains(f.TargetIfAny)) { ((IItem)f.TargetIfAny).Drop(ui, f.PerformedBy, stack.Round); } }
protected override void PopImpl(IWorld world, IUserinterface ui, ActionStack stack, Frame frame) { var f = (CoerceFrame)frame; PrimeWithTarget = null; ((Npc)f.TargetIfAny).NextAction = f; f.TargetIfAny.Adjectives.Add(new Coerced(f)); ui.Log.Info(new LogEntry($"{f.PerformedBy} coerced {f.TargetIfAny} to perform {f.CoerceAction.Name}", stack.Round, frame.PerformedBy)); }
void init_card_Stack() { this.actionStack = new ActionStack(5); this.actionSelection = new ActionStack(0); this.actionStack.actionList.Add(ActionCardStorage.GetForward()); this.actionStack.actionList.Add(ActionCardStorage.GetBackward()); this.actionStack.actionList.Add(ActionCardStorage.GetRotationRight()); this.actionStack.actionList.Add(ActionCardStorage.GetRotationLeft()); this.actionStack.actionList.Add(ActionCardStorage.GetEmpty()); }
public override void Push(IWorld world, IUserinterface ui, ActionStack stack, Wanderer.Actors.IActor actor) { if (ui.GetChoice("Destroy the world", null, out bool chosen, new [] { true, false })) { if (chosen) { stack.Push(new Frame(actor, this, 0)); } } }
public PipelineController(IView view) { _actionStack = new ActionStack(); Selection = new Selection(); View = view; View.Attach(this); ProjectOpen = false; _templateItems = new List<ContentItemTemplate>(); LoadTemplates(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Templates")); }
public PipelineController(IView view, PipelineProject project) { _actionStack = new ActionStack(); Selection = new Selection(); _view = view; _view.Attach(this); _project = project; _project.Controller = this; ProjectOpen = false; _templateItems = new List<ContentItemTemplate>(); LoadTemplates(Environment.CurrentDirectory + "\\Templates"); }
private void Start() { _actionStack = new ActionStack(); //_audio = GetComponent<AudioSource>(); _pixels = new PixelConfig[ColCount, RowCount, DepthCount]; _placeablePixels = new List<PixelConfig>(); var startZ = -1 * (((DepthCount * PixelScale) / 2.0f) - (PixelScale / 2.0f)); var startX = -1 * (((ColCount * PixelScale) / 2.0f) - (PixelScale / 2.0f)); var startY = -1 * (((RowCount * PixelScale) / 2.0f) - (PixelScale / 2.0f)); if ( PixelPrefab ) { for ( int y = 0; y < RowCount; y++ ) { var itemsLeft = (ColCount) * (DepthCount); int x = 0; int z = 0; while ( itemsLeft > 0 ) { int xStartIndex = x; int zStartIndex = z; while ( x < ColCount - xStartIndex ) { AddPixelToPopIn( x, y, z, startX, startY, startZ ); x++; itemsLeft--; } x--; if ( itemsLeft <= 0 ) { break; } z++; while ( z < DepthCount - zStartIndex ) { AddPixelToPopIn( x, y, z, startX, startY, startZ ); z++; itemsLeft--; } z--; if ( itemsLeft <= 0 ) { break; } x--; while ( x >= xStartIndex ) { AddPixelToPopIn( x, y, z, startX, startY, startZ ); x--; itemsLeft--; } x++; if ( itemsLeft <= 0 ) { break; } z--; while ( z >= zStartIndex + 1 ) { AddPixelToPopIn( x, y, z, startX, startY, startZ ); z--; itemsLeft--; } x = xStartIndex + 1; z = zStartIndex + 1; } } } _pixels[ColCount / 2, RowCount / 2, DepthCount / 2].Color = Color.red; //if ( !animatePopIn ) //{ for ( var x = 0; x < ColCount; x++ ) { for ( var y = 0; y < RowCount; y++ ) { for ( var z = 0; z < DepthCount; z++ ) { if ( _pixels[x, y, z].Color.a > 0 ) { PopIn( _pixels[x, y, z] ); } } } } //} DetectPlaceablePixels(); }
protected ActionStackTestContainer(ActionStack stack) { Stack = stack; RegisterEvents(); }
public ActionStackTestContainer(int capacity) { Stack = new ActionStack(capacity); RegisterEvents(); }