public int regenDuration; // The amount of turns the extra regen will be applied to the entity's base regen /// <summary> /// Uses the item (Healing Spray variant) on the specified playable entity and consumes it. /// Being consumed, it will then be removed from the backpack storage (see Backpack class for removal definition). /// </summary> /// <param name="creature">The playable entity this item will be used on.</param> /// <returns>Returns the exit code with the value of the output depending on the state of the entity passed as argument.</returns> public ExitCode Use(PlayableEntity entity) { float health = entity.stats.health; float maxHealth = entity.stats.maxHealth; float regen = entity.stats.healthRegen; // To be usable, the entity's health needs to be between 0 (excluded) and it's max HP (excluded) if (health >= maxHealth) { return(ExitCode.Entity_HP_Maxed); } else if (health <= 0) { return(ExitCode.Entity_Dead); } else { // We heal the entity's health by the healing amount health += fixedHealth; // We add the extra regen to the base regen of the creature regen += this.regen; // We check if the health is higher than the max health of the entity, in which case, we floor it to the max health value if (health > maxHealth) { health = maxHealth; } // We create a new status for the entity entity.statuses.Add(new Status(Status.Type.REGENERATION, regen, regenDuration)); } return(ExitCode.Success); }
public override NoResponse Execute(IMediatorCommand command) { HealCommand _command = this.cast_command(command); PlayableEntity target = _command.GetEntity(); if (_command.Amount < 0) { Console.WriteLine($"WARNING : Trying to heal {target.DisplayName} for {_command.Amount}, will be set to 0 instead"); _command.Amount = 0; } console.Value.AddEntry($"{target.DisplayName} regains {_command.Amount} HPs.\r\n", fontWeightProvider.Value.Bold); _command.From = target.Hp; if (target.Hp + _command.Amount > target.MaxHp) { target.Hp = (int)target.MaxHp; } else { target.Hp += _command.Amount; } _command.To = target.Hp; return(MediatorCommandResponses.NoResponse); }
private void handleHp(TakeDamageCommand command, PlayableEntity target, int remaining) { LooseHpCommand inner_command = new LooseHpCommand(target, remaining); _mediator.Value.Execute(inner_command); command.AddToInnerCommands(inner_command); }
public override ValidableResponse <NoResponse> Execute(IMediatorCommand command) { CastSpellCommand _command = base.cast_command(command); PlayableEntity caster = fighterProvider.Value.GetFighterByDisplayName(_command.CasterName); if (spellLevelSelected(_command) == false) { return(new ValidableResponse <NoResponse>(false, MediatorCommandResponses.NoResponse)); } if (targetsSelected(_command) == false) { return(new ValidableResponse <NoResponse>(false, MediatorCommandResponses.NoResponse)); } if (_command.Spell.IsAnAttack) { if (castAttackSpell(_command) == false) { return(new ValidableResponse <NoResponse>(false, MediatorCommandResponses.NoResponse)); } } else { if (castNonAttackSpell(_command) == false) { return(new ValidableResponse <NoResponse>(false, MediatorCommandResponses.NoResponse)); } } return(new ValidableResponse <NoResponse>(true, MediatorCommandResponses.NoResponse)); }
public MainPlayerInput(PlayableEntity entity) { _entity = entity; _leftTriggered = false; _rightTriggered = false; _upTriggered = false; _downTriggered = false; }
/// <summary> /// Function called to end the Turn of the PlayableEntity /// Will raise the OnEndTurn event /// </summary> public static void EndTurn(this PlayableEntity playableEntity) { playableEntity.InvokeTurnEnded(new TurnEndedEventArgs() { Character = playableEntity, CharacterIndex = FightersList.Instance.Elements.IndexOf(playableEntity), }); }
public void RefreshDamageAffinityModifier(PlayableEntity newTarget) { if (newTarget != null) { foreach (DamageResult result in Elements) { result.AffinityModifier = newTarget.DamageAffinities.GetAffinity(result.DamageType).Affinity; } } }
private Rigidbody2D rbody; //Reference to the players rigidbody public PlayerController(PlayableEntity player) : base(player) { jumpButton = player.jumpButton; lightAttackButton = player.lightAttackButton; attackButton = player.attackButton; dodgeButton = player.dodgeButton; horizontalAxis = player.horizontalAxis; verticalAxis = player.verticalAxis; rbody = player.GetComponent <Rigidbody2D>(); }
/// <summary> /// Adds a unit with the given type and position to this player's information. /// </summary> /// <param name="type">Type of building.</param> /// <param name="x">The x coordinate in the grid.</param> /// <param name="y">The y coordinate in the grid.</param> public void AddUnit(Storage.UnitTypes type, float x, float y) { PlayableEntity e = new PlayableEntity(); e.type.unit = type; e.entityType = Storage.EntityType.UNIT; e.position.X = x; e.position.Y = y; units.Add(e); }
public override ApplyDamageResultListResponse Execute(IMediatorCommand command) { ApplyDamageResultListCommand _command = base.cast_command(command); if (false == _command.DamageList.Any()) { return(null); } PlayableEntity target = _command.GetEntity(); int total = 0; console.Value.AddEntry($"{target.DisplayName}", fontWeightProvider.Value.Bold); console.Value.AddEntry(" takes "); int i = 1; foreach (Damage damage in _command.DamageList) { int final_damage = damage.RawAmount; if (final_damage < 0) { Console.WriteLine($"WARNING : Trying to inflict {final_damage} damage on {target.DisplayName}," + $" will be treated as 0."); final_damage = 0; } applyDamageAffinity(ref final_damage, damage.TypeAffinity); if (_command.LastSavingWasSuccessfull) { applySavingModifier(ref final_damage, damage.SavingModifer); } total += final_damage; if (i == _command.DamageList.Count && i != 1) { console.Value.AddEntry("and "); } console.Value.AddEntry($"{final_damage} {damage.Type}", fontWeightProvider.Value.Bold, colorProvider.Value.GetColorByKey(damage.Type.ToString())); console.Value.AddEntry($"{(i == _command.DamageList.Count ? " damage" : " damage, ")}"); i += 1; } console.Value.AddEntry("\r\n"); TakeDamageCommand inner_command = new TakeDamageCommand(target, total); base._mediator.Value.Execute(inner_command); _command.AddToInnerCommands(inner_command); return(new ApplyDamageResultListResponse(total)); }
private int handleTempHp(TakeDamageCommand command, PlayableEntity target, int remaining) { int amount = remaining < target.TempHp ? remaining : target.TempHp; LooseTempHpCommand inner_command = new LooseTempHpCommand(target, amount); _mediator.Value.Execute(inner_command); command.AddToInnerCommands(inner_command); return(remaining - amount); }
/// <summary> /// Adds a building with the given type and position to this player's information. /// </summary> /// <param name="type">Type of building.</param> /// <param name="x">The x coordinate in the grid.</param> /// <param name="y">The y coordinate in the grid.</param> public void AddBuilding(Storage.BuildingTypes type, float x, float y) { PlayableEntity e = new PlayableEntity(); e.type.building = type; e.entityType = Storage.EntityType.BUILDING; e.position.X = x; e.position.Y = y; e.hasStatus = false; buildings.Add(e); }
/// <summary> /// Adds a building with the given type and position to this player's information. /// </summary> /// <param name="type">Type of building.</param> /// <param name="x">The x coordinate in the grid.</param> /// <param name="y">The y coordinate in the grid.</param> /// <param name="status">The status of the entity.</param> public void AddBuilding(Storage.BuildingTypes type, float x, float y, EntityStatus status) { PlayableEntity e = new PlayableEntity(); e.type.building = type; e.position.X = x; e.position.Y = y; e.hasStatus = true; e.status = status; buildings.Add(e); }
public PlayableEntity GetEntity() { PlayableEntity result = fighterProvider.GetFighterByDisplayName(_entityName); if (result == null) { Console.WriteLine($"ERROR : Trying to execute the command {this.GetType()} on {_entityName} which was no found among Fighters"); throw new NullReferenceException($"Trying to execute the command {this.GetType()} on {_entityName} which was no found among Fighters"); } return(result); }
public PlayableEntity GetEntity() { PlayableEntity result = FightersList.Instance.Elements.FirstOrDefault(x => x.DisplayName == _entityName); if (result == null) { Console.WriteLine($"ERROR : Trying to execute the command {this.GetType()} on {_entityName} which was no found among Fighters"); throw new NullReferenceException($"Trying to execute the command {this.GetType()} on {_entityName} which was no found among Fighters"); } return(result); }
public static void CastSpell(this Spell spell, PlayableEntity caster) { AskPositiveIntWindow levelWindow = new AskPositiveIntWindow(); levelWindow.DescriptionTextBoxControl.Text = "at which level do you wish to cast this spell?"; levelWindow.Number = spell.BaseLevel; levelWindow.ShowCentered(); if (levelWindow.Validated == false) { return; } int level = levelWindow.Number; int additional_levels = level - spell.BaseLevel; int amountTargets = spell.AmountTargets; if (amountTargets != 0) { for (int i = additional_levels; i > 0; i--) { amountTargets += spell.AdditionalTargetPerLevel; } } FightingEntityListSelectableWindow targetWindow = new FightingEntityListSelectableWindow { MaximumSelected = amountTargets, CanSelectSameTargetTwice = spell.CanSelectSameTargetTwice, }; targetWindow.ShowCentered(); if (targetWindow.Validated == true) { if (spell.IsAnAttack) { SpellAttackCastWindow window = new SpellAttackCastWindow() { DataContext = spell.GetAttackSpellResult(caster, targetWindow.Selected, additional_levels) }; window.ShowCentered(); } else { SpellNonAttackCastWindow window = new SpellNonAttackCastWindow() { DataContext = spell.GetNonAttackSpellResult(caster, targetWindow.Selected, additional_levels) }; window.ShowCentered(); } } }
/// <summary> /// Will open a window if a check has to be made for the OnHitStatus to affect the target, then apply the status if required /// </summary> /// <param name="caster"> the one that tries to apply the status </param> /// <param name="target"> the target of the status </param> public static void CheckIfApply(this OnHitStatus onHitStatus, PlayableEntity caster, PlayableEntity target) { if (onHitStatus.HasApplyCondition) { OnHitStatusApplyWindow window = new OnHitStatusApplyWindow(caster, target); window.DataContext = onHitStatus; window.ShowCentered(); } else { onHitStatus.Apply(caster, target); } }
public ApplyDamageResultListCommand(PlayableEntity target, DamageResultList damageList, bool lastSavingWasSuccessfull = false) : base(target.DisplayName) { LastSavingWasSuccessfull = lastSavingWasSuccessfull; foreach (DamageResult dmg in damageList.Elements) { DamageList.Add(new Damage( dmg.Damage.LastResult, dmg.SituationalDamageModifier, dmg.AffinityModifier, dmg.DamageType )); } }
public override void Undo(IMediatorCommand command) { HealCommand _command = this.cast_command(command); if (false == _command.To.HasValue || false == _command.From.HasValue) { Console.WriteLine($"ERROR : Trying to undo a {this.GetType()} command that was not executed first"); throw new NullReferenceException($"Trying to undo a {this.GetType()} command that was not executed first"); } PlayableEntity target = _command.GetEntity(); target.Hp = _command.From.Value; }
/// <summary> /// Functions to ask the PlayableEntity to setup eveyrthing for a new turn /// Will raise the NewTurnStarted event /// </summary> public static void StartNewTurn(this PlayableEntity playableEntity) { playableEntity.HasAction = true; playableEntity.HasReaction = true; playableEntity.HasBonusAction = true; console.NewParagraph(); console.AddEntry(playableEntity.DisplayName, fontWeightProvider.Bold); console.AddEntry("starts its turn!\r\n", fontWeightProvider.Normal); playableEntity.InvokeTurnStarted(new StartNewTurnEventArgs() { Character = playableEntity, CharacterIndex = FightersList.Instance.Elements.IndexOf(playableEntity), }); }
void Init() { if (!init) { if (GameControl.control.playersInScene[playerIndex] != null) { player = GameControl.control.playersInScene[playerIndex].GetComponent <PlayableEntity>(); } else { gameObject.SetActive(false); } if (player != null) { healthBar.sizeDelta = new Vector2(Screen.width / 4.0f - padding, Screen.height / 15.0f); healthBar.GetComponent <Image>().color = player.color2; tempHealthBar.sizeDelta = new Vector2(Screen.width / 4.0f - padding, Screen.height / 15.0f); tempHealthBar.GetComponent <Image>().color = player.color; thisTransform = GetComponent <RectTransform>(); posX = Screen.width / 2.0f; //Middle switch (playerIndex) { case (0): posX = posX - (healthBar.rect.width * 2.0f + padding * 1.5f); break; case (1): posX = posX - (healthBar.rect.width + (padding * 0.5f)); break; case (2): posX = posX + (healthBar.rect.width + (padding * 0.5f)) - healthBar.rect.width; break; case (3): posX = posX + (healthBar.rect.width * 2.0f + padding * 1.5f) - healthBar.rect.width; break; } Vector3 newPosition = Camera.main.ScreenToWorldPoint(new Vector3(posX, 0.0f, 0.0f)); thisTransform.position = new Vector3(newPosition.x, thisTransform.position.y, 0.0f); transform.position = new Vector3(transform.position.x, transform.position.y, 0.0f); initLives(); init = true; } } }
public override NoResponse Execute(IMediatorCommand command) { TempHealCommand _command = this.cast_command(command); PlayableEntity target = _command.GetEntity(); console.Value.AddEntry($"{target.DisplayName} regains {_command.Amount} temporary HPs.\r\n", fontWeightProvider.Value.Bold); _command.From = target.TempHp; if (_command.Amount > target.TempHp) { target.TempHp = _command.Amount; } _command.To = target.TempHp; return(MediatorCommandResponses.NoResponse); }
/// <summary> /// A function that applies this status to the given target /// it will register to any required event for the status to automatically ends /// </summary> /// <param name="caster"> the one that tries to apply the status </param> /// <param name="target"> the target of the status </param> /// <param name="application_success"> tells wether or not the application is a success, only used with "false" to tell the OnApplyDamage can be resisted / canceled </param> /// <param name="multiple_application"> tells that a status will be applied more than once ==> to avoid the removal of concentration on every new affected ==> false for the first call, true for the other ones </param> public static void Apply(this OnHitStatus onHitStatus, PlayableEntity caster, PlayableEntity target, bool application_success = true, bool multiple_application = false) { // the applied status is a copy OnHitStatus applied = (OnHitStatus)onHitStatus.Clone(); if (applied.OnApplyDamageList.Elements.Count != 0) { DamageResultList onApplyDamageList = onHitStatus.OnApplyDamageList.GetResultList(); foreach (DamageResult dmg in onApplyDamageList.Elements) { dmg.LastSavingWasSuccesfull = !application_success; } DamageResultListRollableWindow window = new DamageResultListRollableWindow() { DataContext = onApplyDamageList }; window.ShowCentered(); if (window.Validated) { target.TakeHitDamage(onApplyDamageList); } } if (application_success) { console.AddEntry($"{caster.DisplayName}", fontWeightProvider.Bold); console.AddEntry(" applies "); console.AddEntry($"{onHitStatus.Header}", fontWeightProvider.Bold); console.AddEntry(" on "); console.AddEntry($"{target.DisplayName}\r\n", fontWeightProvider.Bold); applied.Caster = caster; applied.Affected = target; target.CustomVerboseStatusList.AddElementSilent(applied); OnHitStatus.RegisterEvents(applied); if (applied.EndsOnCasterLossOfConcentration) { if (caster.IsFocused == true && multiple_application == false) { caster.IsFocused = false; } caster.IsFocused = true; } } }
private int CountPlayers() { int x = 0; for (int i = 0; i < 4; i++) { if (GameControl.control.playersInScene[i] != null) { PlayableEntity player = GameControl.control.playersInScene[i].GetComponent <PlayableEntity>(); if (player.lives > 0) { x++; } } } return(x); }
private int GetWinner() //Returns -1 if theres no winner. should never happen tho { int x = -1; for (int i = 0; i < 4; i++) { if (GameControl.control.playersInScene[i] != null) { PlayableEntity player = GameControl.control.playersInScene[i].GetComponent <PlayableEntity>(); if (player.lives > 0) { x = i; break; } } } return(x); }
public override NoResponse Execute(IMediatorCommand command) { LooseHpCommand _command = this.cast_command(command); PlayableEntity target = _command.GetEntity(); console.Value.AddEntry($"{target.DisplayName} looses {_command.Amount} HPs.\r\n", fontWeightProvider.Value.Bold); _command.From = target.Hp; target.Hp -= _command.Amount; if (target.Hp < 0) { target.Hp = 0; } _command.To = target.Hp; return(MediatorCommandResponses.NoResponse); }
public override NoResponse Execute(IMediatorCommand command) { LooseTempHpCommand _command = this.cast_command(command); PlayableEntity target = _command.GetEntity(); console.Value.AddEntry($"{target.DisplayName} looses {_command.Amount} temporary HPs.\r\n", fontWeightProvider.Value.Bold); _command.From = target.TempHp; target.TempHp -= _command.Amount; if (target.TempHp < 0) { throw new InvalidOperationException($"WARNING : Trying to remove more TempHps than what {target.DisplayName} has. TempsHps will be set to 0"); } _command.To = target.TempHp; return(MediatorCommandResponses.NoResponse); }
public static void Heal(this PlayableEntity playableEntity, DiceRoll to_roll) { to_roll.Roll(); int amount = to_roll.LastResult; if (playableEntity.Hp + amount >= playableEntity.MaxHp) { amount = (int)playableEntity.MaxHp - playableEntity.Hp; } console.AddEntry(playableEntity.DisplayName, fontWeightProvider.Bold); console.AddEntry(" regains "); console.AddEntry($"{amount}", fontWeightProvider.Bold); console.AddEntry(" Hps.\r\n"); playableEntity.Hp += amount; }
//Collison callback protected override void OnTriggerStay2D(Collider2D other) { if (other.gameObject.tag == "Player1") { if (attacking && canHit) { PlayableEntity defender = other.GetComponent <PlayableEntity>(); if (defender.canHit) { Vector2 knockback = transform.position - defender.transform.position; knockback.Normalize(); knockback *= 100; _rbody.AddForce(knockback); GetComponent <ParticleSystem>().Play(); } //else if(!other.gameObject.GetComponent<PlayableEntity>().invincible) //actionList[(int)attackState].OnHit(other.gameObject.GetComponent<PlayableEntity>()); } } base.OnTriggerStay2D(other); }
public static void HealTempHP(this PlayableEntity playableEntity, DiceRoll to_roll) { to_roll.Roll(); int amount = to_roll.LastResult; console.AddEntry(playableEntity.DisplayName, fontWeightProvider.Bold); if (playableEntity.TempHp < amount) { console.AddEntry(" now has "); console.AddEntry($"{amount}", fontWeightProvider.Bold); console.AddEntry(" temporary Hps.\n"); playableEntity.TempHp = amount; } else { console.AddEntry(" keeps his "); console.AddEntry($"{amount}", fontWeightProvider.Bold); console.AddEntry(" temporary Hps.\n"); } }
/// <summary> /// Constructeur PlayableConcreteEntity /// </summary> /// <param name="pl"> PlayableEntity</param> /// <param name="pls"> PlayableEntitypec</param> public PlayableConcreteEntity(PlayableEntity pl, PlayableEntitySpec pls) : base(pl, pls) { }
/// <summary> /// Adds a building with the given type and position to this player's information. /// </summary> /// <param name="type">Type of building.</param> /// <param name="x">The x coordinate in the grid.</param> /// <param name="y">The y coordinate in the grid.</param> public void AddBuilding(Storage.BuildingTypes type, float x, float y) { PlayableEntity e = new PlayableEntity(); e.type.building = type; e.entityType = Storage.EntityType.BUILDING; e.position.X = x; e.position.Y = y; e.hasStatus = false; buildings.Add(e); }
/// <summary> /// Adds a unit with the given type and position to this player's information. /// </summary> /// <param name="type">Type of building.</param> /// <param name="x">The x coordinate in the grid.</param> /// <param name="y">The y coordinate in the grid.</param> public void AddUnit(Storage.UnitTypes type, float x, float y) { PlayableEntity e = new PlayableEntity(); e.type.unit = type; e.entityType = Storage.EntityType.UNIT; e.position.X = x; e.position.Y = y; units.Add(e); }
/// <summary> /// Adds a building with the given type and position to this player's information. /// </summary> /// <param name="type">Type of building.</param> /// <param name="x">The x coordinate in the grid.</param> /// <param name="y">The y coordinate in the grid.</param> /// <param name="status">The status of the entity.</param> public void AddBuilding(Storage.BuildingTypes type, float x, float y, EntityStatus status) { PlayableEntity e = new PlayableEntity(); e.type.building = type; e.position.X = x; e.position.Y = y; e.hasStatus = true; e.status = status; buildings.Add(e); }