public void Initialize(TurnScheduler scheduler, Entity player, Level activeLevel, System.Action <Level> levelChangeEvent) { health.Initialize(player); clock.Initialize(scheduler); location.Initialize(activeLevel, levelChangeEvent); }
public void SetUp() { turnSchedulerGO = new GameObject("turnScheduler", typeof(TurnScheduler)); turnScheduler = turnSchedulerGO.GetComponent <TurnScheduler>(); tile = MonoBehaviour.Instantiate(TilePrefab, Vector3.zero, Quaternion.identity).GetComponent <Tile>(); unitGO = MonoBehaviour.Instantiate(PlayerPrefab, Vector3.zero, Quaternion.identity); unit = unitGO.GetComponent <PlayerUnit>(); }
public static void Battle(Unit attacker, Unit recipient) { TurnScheduler turnScheduler = GameAssets.MyInstance.turnScheduler; bool hit = new Random().Next(1, 100) <= attacker.stats[StatString.HIT_RATE].Value; bool crit = new Random().Next(1, 100) <= attacker.stats[StatString.CRIT_RATE].Value; if (!recipient.isDead()) { if (hit) { // must take into account whether the main attack is magic or physical int attackDamage = CalculateBaseDamage(attacker, recipient); attackDamage = crit ? attackDamage * CritMultiplier : attackDamage; recipient.TakeDamage(attackDamage); attacker.UseWeapon(); DamagePopUp.Create(recipient.transform.position, string.Format("- {0} HP", (int)attackDamage), PopupType.DAMAGE, crit); } else { DamagePopUp.Create(recipient.transform.position, "MISS!", PopupType.DAMAGE); } } bool killed = false; if (recipient.isDead()) { turnScheduler.StartCoroutine(turnScheduler.RemoveUnit(recipient)); killed = true; } else { recipient.UpdateUI(); } // add exp if (hit) { int exp = Level.CalculateExp(recipient.level, attacker.level, killed); attacker.level.AddExp(exp); } attacker.UpdateUI(); }
public string Post() { string value; using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8)) { value = reader.ReadToEnd(); } try { var direction = StringToDirection(value); IGameState gameState = SessionManager.GetGameState(HttpContext); gameState.Player.SetNextMove(direction); gameState.Map.GetPlayer().SetNextMove(direction); IMoveValidator validator = new MoveValidator(); ICharacterFormatter characterFormatter = new CharacterFormatter(); ITurnScheduler turnScheduler = new TurnScheduler(); IMoveExecutioner moveExecutioner = new MoveExecutioner(new CombatHandler(), new Movement()); IInteractionHandler interactionHandler = new InteractionHandler(); ITurnExecutioner turnExecutioner = new ConcreteTurnExecutioner(validator, characterFormatter, turnScheduler, moveExecutioner, interactionHandler); gameState = turnExecutioner.ExecuteTurn(gameState); // GameState is casted since we only have one valid implementation of gamestate // Interface is for testability (interface needed for mocking) SessionManager.SetGameState(HttpContext, (GameStateClass)gameState); return(JsonConvert.SerializeObject(new ClientGameState(SessionManager.GetGameState(HttpContext)))); } catch (ArgumentException e) { return(e.Message); } }
public EnemyAiRecovery(TurnScheduler turnScheduler) : base(turnScheduler) { }
public EnemyAbility(TurnScheduler turnScheduler) : base(turnScheduler) { _ability = currUnit.chosenAbility; }
public EnemyAiMedic(TurnScheduler turnScheduler) : base(turnScheduler) { }
public TutPlayerStartTurn(TurnScheduler turnScheduler) : base(turnScheduler) { }
public PlayerCaptureCrystal(TurnScheduler turnScheduler) : base(turnScheduler) { }
public EnemyState(TurnScheduler turnScheduler) : base(turnScheduler) { enemyUnit = turnScheduler.enemies.Find(x => x.currentTile == currUnit.currentTile); enemies = turnScheduler.enemies; }
public PlayerAttack(TurnScheduler turnScheduler) : base(turnScheduler) { }
public void HighlightSelectedTiles(HighlightTile mainTile) { // if alr clicked, do nothing: if (clicked) { return; } RemoveSelectedTiles(); // check if tile being hovered is attackable Tile mapStartTile = map.tileList[mainTile.gridPosition.x][mainTile.gridPosition.y]; if (!mapStartTile.attackable) { return; } Ability ability = GameAssets.MyInstance.turnScheduler.currUnit?.chosenAbility; if (ability == null) { ability = new AbilityDefault(); } TargetingStyle targetingStyle = ability.targetingStyle; #region Getting the correct target team IEnumerable <Unit> friendlyTeam; TurnScheduler turnScheduler = GameAssets.MyInstance.turnScheduler; if (turnScheduler.currTurn == Team.ENEMY) { if (ability.targetsSameTeam) { friendlyTeam = turnScheduler.enemies; } else { friendlyTeam = turnScheduler.players; } } else { if (ability.targetsSameTeam) { friendlyTeam = turnScheduler.enemies; } else { friendlyTeam = turnScheduler.players; } } #endregion bool IsFriendlyFire(Tile mapEquivalent) { if (mapEquivalent.occupied) { foreach (Unit unit in friendlyTeam) { if (unit.currentTile == mapEquivalent) { return(true); } } } return(false); } if (targetingStyle == TargetingStyle.MULTI) { int multiAbilityRange = ability.multiAbilityRange; //Debug.Log("multiAbilityRange = " + multiAbilityRange); // init BFS Queue <HighlightTile> processing = new Queue <HighlightTile>(); // Compute Adjacency List and reset all distances. InitPathFinding(mainTile); selectedTiles.Add(mainTile); processing.Enqueue(mainTile); // relax edges with minimum SP estimate while (processing.Count > 0) { HighlightTile node = processing.Dequeue(); foreach (HighlightTile neighbour in node.adjacencyList) { Tile mapEquivalent = map.tileList[neighbour.gridPosition.x][neighbour.gridPosition.y]; if (mapEquivalent.walkable && neighbour.distance > node.distance + 1 && node.distance + 1 <= multiAbilityRange) { if (!IsFriendlyFire(mapEquivalent)) { neighbour.distance = node.distance + 1; selectedTiles.Add(neighbour); processing.Enqueue(neighbour); } } } } } else if (targetingStyle == TargetingStyle.SINGLE || targetingStyle == TargetingStyle.SELF || targetingStyle == TargetingStyle.SELFSINGLE) { Tile mapEquivalent = map.tileList[mainTile.gridPosition.x][mainTile.gridPosition.y]; if (!IsFriendlyFire(mapEquivalent)) { selectedTiles.Add(mainTile); } } else if (targetingStyle == TargetingStyle.RADIUS) { foreach (Tile tile in map.GetAttackableTiles()) { if (!IsFriendlyFire(tile)) { selectedTiles.Add(tileList[tile.gridPosition.x][tile.gridPosition.y]); } } } else if (targetingStyle == TargetingStyle.OBSTACLES) { if (map.tileCostReference.IsObstacle(mainTile.transform.position)) { selectedTiles.Add(mainTile); } } foreach (HighlightTile tile in selectedTiles) { tile.hover = true; } }
public CutScene(TurnScheduler turnScheduler) : base(turnScheduler) { }
public PlayerWin(TurnScheduler turnScheduler) : base(turnScheduler) { }
public EnemyAiWait(TurnScheduler turnScheduler) : base(turnScheduler) { }
public EnemyAiCautiousMovement(TurnScheduler turnScheduler) : base(turnScheduler) { }
private static void GenerateSampleTemplate() { Assets.LoadAssets(); GameObject mockGo = new GameObject(); GameObject fxShrapnelPrefab = new GameObject("FX_Shrapnel"); TurnScheduler scheduler = mockGo.AddComponent <TurnScheduler>(); Locator.Scheduler = scheduler; EntityComponent[] components = new EntityComponent[] { new Actor() { Control = ActorControl.None }, new AI(new ApproachUtility(), new AttackUtility(), new FleeUtility()), new Ammo() { Type = AmmoType.Cartridges, Damages = new Damage[] { new Damage() { Type = DamageType.Piercing, Min = 3, Max = 7 } }, OnLandCommand = new ExplodeCommand(null) { Prefab = fxShrapnelPrefab, Pattern = ExplosionPattern.Square, Damages = new Damage[] { new Damage() { Type = DamageType.Searing, Min = 3, Max = 7 } } }, }, new Body(), new Corpse(), new Dialogue(), new Evocable(), new Health(), new Inventory(20), new Location(), new Melee( new MeleeAttack( new Damage[] { new Damage() { Type = DamageType.Slashing, Min = 2, Max = 5 } }, 80, 120)), new OnDamageTaken(), new OnUse(TurnScheduler.TurnTime), new Relic() { Name = "Orb of Zot" }, new Size(1), new Species(null), new Splat() { Sound = null }, new Status(), new Talented() { Talents = new Talent[] { new Talent() { ID = "Talent_Foobar" }, } }, new Weight(50), new Wield(2) }; EntityTemplate template = new EntityTemplate { ID = "SAMPLE_ID", EntityName = "SAMPLE_NAME", Flags = EntityFlag.Unique | EntityFlag.Blocking, Components = components, Inventory = new EntityTemplate[] { new EntityTemplate { ID = "Item_SampleItem" } }, Wielded = new EntityTemplate[] { new EntityTemplate { ID = "Item_SampleWeapon" } } }; string path = Application.dataPath + $"/Sample/sample_template.json"; if (File.Exists(path)) { File.Delete(path); } JsonSerializerSettings settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto, SerializationBinder = Binders._entity, Formatting = Formatting.Indented, Converters = new List <JsonConverter>() { new GameObjectConverter(), new SpriteConverter(), new TalentConverter(), new TileConverter(), new RuleTileConverter(), new SpeciesDefinitionConverter(), new BodyPartConverter(), new StatusConverter() } }; File.AppendAllText(path, JsonConvert.SerializeObject(template, settings)); AssetDatabase.Refresh(); Object.DestroyImmediate(mockGo as GameObject); Object.DestroyImmediate(fxShrapnelPrefab as GameObject); Debug.Log($"Wrote sample template with all components to {path}."); Assets.UnloadAssets(); }
public EnemyAiAggressive(TurnScheduler turnScheduler) : base(turnScheduler) { }
public TutPlayerUnitSelected(TurnScheduler turnScheduler) : base(turnScheduler) { }
public PlayerAttackTargeting(TurnScheduler turnScheduler) : base(turnScheduler) { }
public State(TurnScheduler turnScheduler) { this.turnScheduler = turnScheduler; this.map = turnScheduler.map; this.currUnit = turnScheduler.currUnit; }
public void Initialize(TurnScheduler scheduler) { scheduler.TimeChangeEvent += Redraw; Redraw(scheduler.Time, 0); }
public Transition(TurnScheduler turnScheduler) : base(turnScheduler) { }
public EnemyEndTurn(TurnScheduler turnScheduler) : base(turnScheduler) { }
public PlayerInventoryMenu(TurnScheduler turnScheduler) : base(turnScheduler) { }
public PlayerAbility(TurnScheduler turnScheduler) : base(turnScheduler) { _ability = turnScheduler.currUnit.chosenAbility; }
public TutPlayerAbilityTargeting(TurnScheduler turnScheduler) : base(turnScheduler) { ability = turnScheduler.currUnit.chosenAbility; }
public EnemyStartTurn(TurnScheduler turnScheduler) : base(turnScheduler) { }
public TutPlayerAbilityMenu(TurnScheduler turnScheduler) : base(turnScheduler) { }
public TutPlayerEndTurn(TurnScheduler turnScheduler) : base(turnScheduler) { }