public IAdjective Create(IWorld world, IHasStats s, string name) { //when creating by name allow type names too var type = _adjectiveTypes.FirstOrDefault(t => t.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); return(type != null?Create(s, type) : Create(world, s, GetBlueprint(name))); }
public IAdjective Create(IWorld world, IHasStats s, AdjectiveBlueprint blueprint) { HandleInheritance(blueprint); var adj = new Adjective(s) { Name = blueprint.Name }; base.AddBasicProperties(world, adj, blueprint, "inspect"); if (blueprint.StatsRatio != null) { adj.StatsRatio = blueprint.StatsRatio; } if (blueprint.Resist != null) { adj.Resist = blueprint.Resist; } adj.IsPrefix = blueprint.IsPrefix; s.Adjectives.Add(adj); return(adj); }
/// <summary> /// Calculates how susceptible something is based on the current /// resistances (<see cref="Immune"/> etc). /// </summary> /// <param name="s"></param> /// <returns>0 for immunity, 1 for normal. 0.5 for resist and 2 for vulnerable</returns> public double Calculate(IHasStats s) { //if you are immune if (Immune.Any(s.Has)) { return(0); } bool resist = Resist.Any(s.Has); bool vuln = Vulnerable.Any(s.Has); if (resist && vuln) { return(1); } if (resist) { return(0.5); } if (vuln) { return(2); } //neither resistant nor vulnerable return(1); }
public IBehaviour Create(IWorld world, IHasStats onto, BehaviourBlueprint blueprint) { base.HandleInheritance(blueprint); var instance = new Behaviour(onto) { Name = blueprint.Name }; AddBasicProperties(world, instance, blueprint, "evaluate"); // events if (blueprint.OnPop != null) { instance.OnPopHandler = blueprint.OnPop.Create(); } if (blueprint.OnPush != null) { instance.OnPushHandler = blueprint.OnPush.Create(); } if (blueprint.OnRoundEnding != null) { instance.OnRoundEndingHandler = blueprint.OnRoundEnding.Create(); } if (blueprint.OnEnter != null) { instance.OnEnterHandler = blueprint.OnEnter.Create(); } onto.BaseBehaviours.Add(instance); return(instance); }
public override void ApplyEffect() { // get the base stat value of the user of this effect int baseValue = 0; if (StatBase != 0) // prevents people forgetting to give a stat base name { IHasStats owner = Source.GetOwner().GetComponent <IHasStats>(); if (owner != null) { owner.TryGetStatValue(StatBase, out baseValue); // prevents the case where the statname doesn't exist } } // apply effect to target IHasTargetEffects targetSource = Source as IHasTargetEffects; if (targetSource != null) { if (targetSource.GetTarget() != null) { IHasStats target = targetSource.GetTarget().GetComponent <IHasStats> (); if (target != null) { target.ModifyStat(StatBase, TargetStat, Modifier, FlatValue, baseValue); } } } }
/// <summary> /// Skill coroutine. /// go through all skill effects and apply the effect at the appropriate time. /// </summary> public IEnumerator SkillCoroutine() { if (!IsValid()) { yield return(null); } // apply all prerequisites IHasStats statOwner = Owner.GetComponent <IHasStats> (); if (statOwner == null) { yield return(null); } for (int i = 0; i < Prerequisites.Count; i++) { Prerequisites [i].ApplyPrerequisite(statOwner); } Debug.Log("Using " + Name); // apply all effects float startTime = Time.time; float curDelay = 0.0f; for (int i = 0; i < Effects.Count; i++) { yield return(new WaitForSeconds(Effects [i].Delay - curDelay)); Effects [i].ApplyEffect(); curDelay = Effects[i].Delay; } yield return(new WaitForSeconds(Delay - (Time.time - startTime))); }
public void ValidateDialogue(IWorld world, IHasStats recipient, DialogueInitiation dialogue, IRoom room) { if (dialogue.Next.HasValue) { var d = world.Dialogue.GetDialogue(dialogue.Next); if (d == null) { AddError($"Could not find Dialogue '{dialogue.Next}'"); } else { ValidateDialogue(world, recipient, dialogue, d, room); } } if (dialogue.Banter != null) { foreach (var guid in dialogue.Banter) { var d = world.Dialogue.GetDialogue(guid); if (d == null) { AddError($"Could not find Banter Dialogue '{dialogue.Next}'"); } else { ValidateDialogue(world, recipient, dialogue, d, room); } } } }
//---------------------------------------------------------------------------- // Initialise //---------------------------------------------------------------------------- #region Initialise public void Initialise() { Equipment equipment = GetComponent <Equipment>(); MyWeapon = equipment.MyWeapon; IHasStats hasStats = GetComponent <IHasStats>(); int hitBonusInt = 0; if (hasStats.IsProficient(MyWeapon.MyWeaponType)) { hitBonusInt += hasStats.ProficiencyBonus; } hitBonusInt += hasStats.GetAttackMod(MyWeapon); ToHitBonus toHitBonus = new ToHitBonus(hitBonusInt); MyAlterationManager.MyAttackDataAlterer.AddAttackAlteration(this, toHitBonus); int damageStatModInt = hasStats.GetAttackMod(MyWeapon); DamageStatMod damageStatMod = new DamageStatMod(damageStatModInt); MyAlterationManager.MyDamageDataAlterer.RegisterDamageAlteration(this, damageStatMod); }
public SystemArgs(IWorld world, IUserinterface ui, double intensity, IActor aggressorIfAny, IHasStats recipient, Guid round) { World = world; Intensity = intensity; AggressorIfAny = aggressorIfAny; Recipient = recipient; Round = round; UserInterface = ui; }
public void Initialise() { IHasStats hasStats = GetComponent <IHasStats>(); hasStats.AddSimpleWeaponsProficiency(); hasStats.AddArmorProficiency(ArmorType.Light); hasStats.AddArmorProficiency(ArmorType.Medium); hasStats.AddArmorProficiency(ArmorType.Shield); }
private double GetOperand(SystemArgs args, IHasStats hasStats, string operand) { if (args.World.AllStats.Contains(operand)) { return(hasStats.BaseStats[operand]); } return(hasStats.V[operand]); }
private bool ValidatePick(IActor actor, IHasStats target, out string reason) { if (target is IItem i && !i.CanUse(actor, out reason)) { return(false); } reason = null; return(true); }
public override bool GetStatus(){ if (Owner == null) return false; IHasStats ownerStat = Owner.GetComponent<IHasStats> (); float curValue; if (!ownerStat.TryGetStatPercentValue (StatName, out curValue)) return false; else return curValue < StatValue; }
public ActionFrameSystemArgs(IHasStats source, IWorld world, IUserinterface ui, ActionStack stack, Frame frame) : base(source, world, ui, frame.PerformedBy, frame.TargetIfAny ?? frame.PerformedBy, stack.Round) { Stack = stack; Frame = frame; if (Action == null) { Action = frame.Action; } }
/// <summary> /// Creates a new <see cref="IAction"/> based on the <paramref name="blueprint"/> and adds it as a <see cref="IHasStats.BaseActions"/> /// </summary> /// <param name="world"></param> /// <param name="onto"></param> /// <param name="blueprint"></param> /// <returns></returns> public IAction Create(IWorld world, IHasStats onto, ActionBlueprint blueprint) { HandleInheritance(blueprint); IAction action; if (string.IsNullOrWhiteSpace(blueprint.Type)) { action = new Action(onto); } else { try { var type = _types.GetTypeNamed(blueprint.Type); action = (IAction)Activator.CreateInstance(type, onto); } catch (Exception ex) { throw new Exception($"Error creating base Type for ActionBlueprint {blueprint}", ex); } } AddBasicProperties(world, action, blueprint, "use"); if (!string.IsNullOrWhiteSpace(blueprint.Name)) { action.Name = blueprint.Name; } action.Owner = onto; if (blueprint.HotKey.HasValue) { action.HotKey = blueprint.HotKey.Value; } action.Effect.AddRange(blueprint.Effect.SelectMany(e => e.Create())); if (blueprint.Targets != null) { action.Targets = blueprint.Targets; } action.TargetPrompt = blueprint.TargetPrompt; if (action is FightAction fight && blueprint.InjurySystem.HasValue) { fight.InjurySystem = (IInjurySystem)world.GetSystem(blueprint.InjurySystem.Value); } onto.BaseActions.Add(action); return(action); }
public Injured(string name, IHasStats owner, double severity, InjuryRegion region, IInjurySystem system) : base(owner) { Severity = severity; Region = region; IsPrefix = false; InjurySystem = system; BaseStats[Stat.Fight] = -0.5 * severity; Name = name; BaseBehaviours.Add(new InjuredBehaviour(this)); }
/// <summary> /// Modifies the <paramref name="chosen"/> action setting it's choice of target to <paramref name="target"/> /// </summary> /// <param name="chosen"></param> /// <param name="target"></param> public void PrimeCommandWithTarget(IAction chosen, IHasStats target) { if (chosen is FightAction f) { f.PrimeWithTarget = target as IActor; } if (chosen is PickUpAction p) { p.PrimeWithTarget = target as IItem; } if (chosen is CoerceAction c) { c.PrimeWithTarget = target as IActor; } }
public void ShowStats(IHasStats of) { if (of == null) { ShowMessage("No World", "No game is currently loaded"); return; } var v = new HasStatsView(); v.InitializeComponent(of as IActor ?? World.Player, of, DlgWidth, DlgHeight); var dlg = new ModalDialog(this, of.Name, v); Application.Run(dlg); }
/// <summary> /// Checks the conditions of the gambit. updates IsReady /// </summary> public void CheckConditions() { if ((MaxUse != -1) && (UsageNumber >= MaxUse)) { IsReady = false; return; } if (Skill == null) { IsReady = false; return; } if (!Skill.IsPrerequisitesMet()) { IsReady = false; return; } IHasStats levelledOwner = Owner.GetComponent <IHasStats>(); if (levelledOwner == null) { IsReady = false; return; } else if (levelledOwner.GetStatLevel() < Skill.RequiredLevel) { IsReady = false; return; } if (Skill.CurrentCooldown < Skill.Cooldown) { IsReady = false; return; } IsReady = true; int i = 0; while (IsReady && (i < Conditions.Count)) { IsReady = IsReady && Conditions [i].GetStatus(); i++; } }
public StatsManager GetStats() { if (wielder == null) { return(null); } IHasStats statWielder = wielder as IHasStats; if (statWielder == null) { return(null); } return(statWielder.GetStats()); }
public void ValidateAction(IWorld world, IHasStats owner, IAction action, IRoom room) { var actor = owner as IActor ?? GetTestActor(room); foreach (var effect in action.Effect) { try { effect.Apply(new ActionSystemArgs(action, world, _ui, 0, GetTestActor(room), actor, Guid.Empty)); } catch (Exception e) { AddWarning($"Error testing Effect Code of Action '{action}' of '{owner}'. Bad code was:{effect}", e); } } }
public virtual void ShowStats(IHasStats of) { Console.WriteLine(of.ToString()); Console.WriteLine("Adjectives:" + string.Join(",", of.Adjectives)); Console.WriteLine("Stats:" + string.Join(Environment.NewLine, of.BaseStats.Select(s => s.Key.ToString() + ':' + s.Value))); if (of is IActor a) { Console.WriteLine("Items:" + string.Join(",", a.Items)); } if (of is IRoom r) { Console.WriteLine("Items:" + string.Join(",", r.Items)); } }
public override void ApplyEffect() { // get the base stat value of the user of this effect int baseValue = 0; if (StatBase != "") // prevents people forgetting to give a stat base name { IHasStats owner = Source.GetOwner().GetComponent <IHasStats>(); if (owner != null) { owner.TryGetStatValue(StatBase, out baseValue); // prevents the case where the statname doesn't exist } } // get source as a targettable source IHasTargetEffects targetSource = Source as IHasTargetEffects; if (targetSource == null) { return; } // get source owner IHasPerception perceptionOwner = Source.GetOwner().GetComponent <IHasPerception>(); if (perceptionOwner == null) { return; } // for each found percept, if the tag is inside the target type mask, process foreach (var percept in perceptionOwner.Perception.Percepts.Values) { IPerceivable perceivable = percept.Entity.GetComponent <IPerceivable>(); if (perceivable != null && ((perceivable.Tag & TargetType) != 0) && (Vector3.Magnitude(percept.Entity.transform.position - targetSource.GetTarget().transform.position) <= Radius)) { if (percept.Entity != targetSource.GetTarget() || IncludeTarget) { IHasStats target = percept.Entity.GetComponent <IHasStats> (); if (target != null) { target.ModifyStat(TargetStat, Modifier, FlatValue, baseValue); } } } } }
public void ValidateDialogue(IWorld world, IHasStats recipient, DialogueInitiation dialogue, DialogueNode node, IRoom room) { if (_alreadyValidated.Contains(node.Identifier)) { return; } _alreadyValidated.Add(node.Identifier); if (node.Body == null || node.Body.Count == 0 || node.Body.All(b => string.IsNullOrWhiteSpace(b.Text))) { AddError($"Dialogue '{node.Identifier}' has no Body Text"); } foreach (ICondition condition in node.Condition) { try { condition.IsMet(world, new SystemArgs(world, _ui, 0, GetTestActor(room), recipient, Guid.Empty)); } catch (Exception e) { AddWarning($"Error testing dialogue condition on '{node}' for test actor interacting with '{recipient}'", e); } } if (node.Body != null) { foreach (ICondition condition in node.Body.SelectMany(b => b.Condition)) { try { condition.IsMet(world, new SystemArgs(world, _ui, 0, GetTestActor(room), recipient, Guid.Empty)); } catch (Exception e) { AddWarning($"Error testing dialogue BodyText Condition on '{node}' for test actor interacting with '{recipient}'", e); } } } foreach (var option in node.Options) { Validate(world, recipient, dialogue, room, node, option); } }
public void AddAdjectives(IWorld world, IHasStats owner, HasStatsBlueprint ownerBlueprint) { //Adjectives the user definitely wants included if (ownerBlueprint.MandatoryAdjectives.Any()) { foreach (var a in ownerBlueprint.MandatoryAdjectives) { Create(world, owner, a); } } //pick 1 random adjective if blueprint lists any to pick from if (ownerBlueprint.OptionalAdjectives.Any()) { Create(world, owner, ownerBlueprint.OptionalAdjectives.GetRandom(world.R)); } }
public void ValidateBehaviour(IWorld world, IHasStats owner, IBehaviour behaviour, IRoom room) { var actor = owner as IActor ?? GetTestActor(room); var testAction = new Action(actor) { Name = "Test Action" }; var stack = new ActionStack(); try { behaviour.OnPush(world, _ui, stack, new Frame(actor, testAction, 0)); } catch (Exception e) { AddWarning($"Error testing OnPush of Behaviour {behaviour} of on '{owner}' in room '{room.Name}' with test actor '{actor}'", e); } try { behaviour.OnPop(world, _ui, stack, new Frame(actor, testAction, 0)); } catch (Exception e) { AddWarning($"Error testing OnPop of Behaviour {behaviour} of on '{owner}' in room '{room.Name}' with test actor '{actor}'", e); } try { behaviour.OnRoundEnding(world, _ui, Guid.NewGuid()); } catch (Exception e) { AddWarning($"Error testing OnRoundEnding of Behaviour {behaviour} of on '{owner}' in room '{room.Name}' with test actor '{actor}'", e); } try { behaviour.OnEnter(world, _ui, Guid.NewGuid(), actor, room); } catch (Exception e) { AddWarning($"Error testing OnEnter of Behaviour {behaviour} of on '{owner}' in room '{room.Name}' with test actor '{actor}'", e); } }
public void SetAC(IIsVictim isVictim, IACAlterer acAlterer) { Equipment equipment = gameObject.GetComponent <Equipment>(); ArmorObject armorObject = equipment.MyArmor; int mod = armorObject.BaseAC; IHasStats hasStats = gameObject.GetComponent <HasStats>(); int dexMod = hasStats.GetStatMod(StatsType.Dexterity); if (armorObject.HasMaxDexMod && (dexMod > armorObject.MaxDexMod)) { dexMod = armorObject.MaxDexMod; } mod += dexMod; acAlterer.AddACMod(isVictim, mod); }
/// <summary> /// Prompts for all choices and then pushes onto <paramref name="stack"/> /// a suitable <see cref="Frame"/> (or not if there are no valid options picked / option /// picking is cancelled. /// /// <para>Actual resolution of the action should be reserved for the <see cref="Pop"/> method</para> /// </summary> /// <param name="world"></param> /// <param name="ui"></param> /// <param name="stack"></param> /// <param name="actor"></param> public virtual void Push(IWorld world, IUserinterface ui, ActionStack stack, IActor actor) { var targets = GetTargets(actor).ToArray(); IHasStats target = Owner; if (targets.Length >= 1) { if (!actor.Decide(ui, Name, TargetPrompt, out target, targets, Attitude)) { return; } } stack.Push(new Frame(actor, this, GetAttitude(actor, target) ?? Attitude) { TargetIfAny = target }); }
public override bool GetStatus() { if (Owner == null) { return(false); } IHasStats ownerStat = Owner.GetComponent <IHasStats> (); float curValue; if (!ownerStat.TryGetStatPercentValue(StatName, out curValue)) { return(false); } else { return(curValue < StatValue); } }
public override void ApplyEffect() { Debug.Log("applying room wide stat effect"); // get the base stat value of the user of this effect int baseValue = 0; if (StatBase != "") // prevents people forgetting to give a stat base name { IHasStats owner = Source.GetOwner().GetComponent <IHasStats>(); if (owner != null) { owner.TryGetStatValue(StatBase, out baseValue); // prevents the case where the statname doesn't exist } } // if the owner doesn't have a perception component, it sees nothing basically, nothing can be affected IHasPerception perceptionOwner = Source.GetOwner().GetComponent <IHasPerception>(); if (perceptionOwner == null) { return; } // for each found percept, if the tag is inside the target type mask, process foreach (var percept in perceptionOwner.Perception.Percepts.Values) { IPerceivable perceivable = percept.Entity.GetComponent <IPerceivable>(); if (perceivable != null && ((perceivable.Tag & TargetType) != 0)) { if (percept.Entity != Source.GetOwner() || IncludeSelf) { // this effect should only apply to perceivable that has stats component IHasStats target = percept.Entity.GetComponent <IHasStats> (); if (target != null) { target.ModifyStat(TargetStat, Modifier, FlatValue, baseValue); } } } } }