示例#1
0
文件: Tile.cs 项目: Cobalte/Tactics
    //----------------------------------------------------------------------------------------------
    private void OnMouseDown()
    {
        if (IsMarked)
        {
            // if a unit has an ability selected, execute it on this tile
            if (UnitRoster.SelectedAbility != null)
            {
                UnitRoster.IssueSelectedAbilityOrder(targetTile: this);
            }
            // if a unit is selected, move it to this tile
            else if (UnitRoster.SelectedUnit != null)
            {
                UnitRoster.IssueSelectedUnitMoveOrder(this);
            }
            else
            {
                Debug.LogError("User clicked a marked tile with no selected unit or ability.");
            }
        }

        // if there's a unit here, select it
        else if (GetOccupyingUnit() != null)
        {
            UnitRoster.SelectUnit(GetOccupyingUnit());
        }
    }
示例#2
0
    //----------------------------------------------------------------------------------------------
    private void HandlePlayerInputs()
    {
        // handle global escape key
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            UnitRoster.SelectUnit(null);
        }

        // if the user pressed a valid ability hotkey, select that ability
        for (int i = 0; i < CanvasReferences.abilityFrames.Length; i++)
        {
            if (CanvasReferences.abilityFrames[i].gameObject.activeSelf &&
                Input.GetKeyDown(CanvasReferences.abilityFrames[i].Hotkey))
            {
                UnitRoster.SelectAbilityForSelectedUnit(i);
                break;
            }
        }

        // if the player pressed 'skip turn' then skip their turn
        if (Input.GetKeyDown(KeyCode.X))
        {
            foreach (Unit unit in UnitRoster.GetUnitsForOwner(Player.HumanPlayer))
            {
                unit.HasActed = true;
                unit.HasMoved = true;
            }
        }
    }
示例#3
0
        public void TestGetUnitsInfo()
        {
            UnitRoster playerUnits = session.GetPlayerUnits();

            Assert.IsTrue(playerUnits.GetAllUnits().Count == 3, "Found more units than expected. (Expecting 3)");

            Assert.AreEqual(playerUnits.GetAllUnits().Find(s => s.InternalName.Equals("Hector")).InternalName, "Hector", "Could not find Hector");
            Assert.AreEqual(playerUnits.GetAllUnits().Find(s => s.InternalName.Equals("Eliwood")).InternalName, "Eliwood", "Could not find Eliwood");
            Assert.AreEqual(playerUnits.GetAllUnits().Find(s => s.InternalName.Equals("Serra")).InternalName, "Serra", "Could not find Serra");

            UnitRoster playerUnits2 = session.GetUnits(UnitTeam.team1);

            Assert.IsTrue(playerUnits2.GetAllUnits().Count == 3, "2 Found more units than expected. (Expecting 3)");

            Assert.AreEqual(playerUnits2.GetAllUnits().Find(s => s.InternalName.Equals("Hector")).InternalName, "Hector", "2 Could not find Hector");
            Assert.AreEqual(playerUnits2.GetAllUnits().Find(s => s.InternalName.Equals("Eliwood")).InternalName, "Eliwood", "2 Could not find Eliwood");
            Assert.AreEqual(playerUnits2.GetAllUnits().Find(s => s.InternalName.Equals("Serra")).InternalName, "Serra", "2 Could not find Serra");


            UnitRoster enemyUnits = session.GetUnits(UnitTeam.team2);

            Assert.IsTrue(enemyUnits.GetAllUnits().Count == 4, "Found more units than expected. (Expecting 4)");

            Assert.AreEqual(enemyUnits.GetAllUnits().Find(s => s.InternalName.Equals("Erik")).InternalName, "Erik", "Could not find Erik");

            try
            {
                UnitRoster noSuchTeam = session.GetUnits(UnitTeam.team5);
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(KeyNotFoundException), "Able to get roster for non-existing team");
            }
        }
示例#4
0
        public void TestAddDuplicateUnits()
        {
            UnitRoster roster = new UnitRoster(null, UnitTeam.team1);
            UnitEntity mu     = new UnitEntity();

            Assert.IsTrue(roster.AddUnit(mu), "Original add unit not successful");
            Assert.IsFalse(roster.AddUnit(mu), "Duplicate add unit was not prevented");
        }
示例#5
0
文件: Unit.cs 项目: Cobalte/Tactics
    //----------------------------------------------------------------------------------------------
    private void Start()
    {
        if (UnitData == null)
        {
            throw new Exception("Unit '" + gameObject.name + "' tried to Start() with no unit data.");
        }

        UnitRoster.RegisterUnit(this);
        Body = new UnitBody();
        Body.Initialize(this);
    }
示例#6
0
        public void TestStartTurn()
        {
            session.StartTurn(UnitTeam.team1);

            UnitRoster playerUnits = session.GetPlayerUnits();

            foreach (UnitEntity ue in playerUnits.GetAllUnits())
            {
                Assert.IsTrue(ue.HasActed == false, "Unit not ready to act");
            }
        }
示例#7
0
        public void TestFindUnitByName()
        {
            UnitRoster roster = new UnitRoster(null, UnitTeam.team1);
            UnitEntity mu     = new UnitEntity();
            string     name   = "Sebastian";

            mu.InternalName = name;

            roster.AddUnit(mu);
            Assert.AreEqual(mu, roster.GetUnitByName(name), "Roster GetUnitByName was not successful");
        }
示例#8
0
        public void TestGetAllUnits()
        {
            UnitRoster roster = new UnitRoster(null, UnitTeam.team1);
            UnitEntity mu;

            mu = new UnitEntity();
            roster.AddUnit(mu);
            mu = new UnitEntity();
            roster.AddUnit(mu);
            Assert.AreEqual(2, roster.GetAllUnits().Count, "Multiple add units not supported");
        }
示例#9
0
        public void TestAddUnits()
        {
            UnitRoster constructorRoster = new UnitRoster(new UnitEntity[1] {
                new UnitEntity()
            }, UnitTeam.team1);

            Assert.AreEqual(1, constructorRoster.GetAllUnits().Count, "Roster constructor add unit was not successful");

            UnitRoster roster = new UnitRoster(null, UnitTeam.team1);
            UnitEntity mu     = new UnitEntity();

            Assert.IsTrue(roster.AddUnit(mu), "Roster add unit was not successful");
        }
示例#10
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }
        roster = StarterDatabase.GetDictionary(0);

        activeRoster = new List <Character>();
        foreach (KeyValuePair <string, Character> c in roster)
        {
            activeRoster.Add(c.Value);
        }
        train = new Train();
    }
示例#11
0
        public void TestEndTurn()
        {
            session.StartTurn(session.PlayerTeam);

            UnitRoster playerUnits = session.GetPlayerUnits();

            foreach (UnitEntity ue in playerUnits.GetAllUnits())
            {
                Assert.IsTrue(ue.HasActed == false, "2 Unit not ready to act");
            }

            session.EndPlayerTurn();

            playerUnits = session.GetPlayerUnits();
            foreach (UnitEntity ue in playerUnits.GetAllUnits())
            {
                Assert.IsTrue(ue.HasActed == true, "3 Unit still waiting to act");
            }
        }
示例#12
0
    /// <summary>
    /// Save the game with supplied filename and marks a checkpoint
    /// also saves all character in the UnitRoster
    /// </summary>
    public void Save(string filename)
    {
        //Preparing save data
        SaveData saveData = new SaveData();

        saveData.Checkpoint = checkPoint;
        UnitRoster roster = GetComponent <UnitRoster>();

        saveData.Roster = new List <SaveCharacter>();
        foreach (KeyValuePair <string, Character> pair in roster.Roster)
        {
            SaveCharacter temp;
            temp           = new SaveCharacter();
            temp.name      = pair.Key;
            temp.character = new Character(pair.Value);
            GearPackage tempBackPack = new GearPackage(pair.Value.Backpack);
            temp.backpack = tempBackPack;
            if (roster.activeRoster.Contains(pair.Value))
            {
                temp.isActive = true;
            }
            else
            {
                temp.isActive = false;
            }
            temp.skills = new SkillTree(pair.Value.Skilltree);
            saveData.Roster.Add(temp);
        }
        GearPackage train = new GearPackage(roster.train);

        saveData.train    = train;
        saveData.saveTime = DateTime.Now;
        //Now let's write it to a file
        BinaryFormatter binary = new BinaryFormatter();

        Debug.Log(Application.persistentDataPath);
        FileStream file = File.Create(Application.persistentDataPath + "/" + filename + ".sav");

        binary.Serialize(file, saveData);
        file.Close();
    }
示例#13
0
    /// <summary>
    /// Load a game from provided filename from the checkpoint being stored in this class
    /// and stuffs all character info from the savefile into the UnitRoster
    /// </summary>
    public void Load(string filename)
    {
        BinaryFormatter binary   = new BinaryFormatter();
        FileStream      file     = File.Open(Application.persistentDataPath + "/" + filename + ".sav", FileMode.Open);
        SaveData        saveData = (SaveData)binary.Deserialize(file);

        file.Close();
        checkPoint = saveData.Checkpoint;
        UnitRoster roster = GetComponent <UnitRoster>();

        roster.activeRoster.Clear();
        List <Character> savedRoster = new List <Character>();

        foreach (SaveCharacter character in saveData.Roster)
        {
            Character tempUnit = character.character;
            Character baseChar = roster.getBaseCharacter(character.name);
            if (tempUnit != null)
            {
                tempUnit = character.character;
                if (character.isActive)
                {
                    roster.activeRoster.Add(tempUnit);
                }
                Backpack tempBackPack = character.backpack.GetBackpack();
                tempUnit.Backpack  = tempBackPack;
                tempUnit.Skilltree = new SkillTree(character.skills);
                tempUnit.Sprite    = baseChar.Sprite;
                tempUnit.MugShot   = baseChar.MugShot;
            }
            else
            {
                Debug.LogError("No characters in loaded file?");
                return;
            }
            savedRoster.Add(tempUnit);
        }
        roster.train = saveData.train.GetTrain();
    }
示例#14
0
        public void TestAddRoster()
        {
            UnitBook book = new UnitBook(UnitTeam.team1);

            UnitRoster rosterOne = new UnitRoster(null, UnitTeam.team1);
            UnitEntity mu1       = new UnitEntity();

            rosterOne.AddUnit(mu1);

            //expect success the first time
            Assert.IsTrue(book.AddRoster(rosterOne, TeamRelation.player), "Roster not added to GameMap");

            //and failure the next
            Assert.IsFalse(book.AddRoster(rosterOne, TeamRelation.player), "Duplicate roster added");

            UnitRoster rosterTwo = new UnitRoster(null, UnitTeam.team2);
            UnitEntity mu2       = new UnitEntity();

            rosterTwo.AddUnit(mu2);

            Assert.IsTrue(book.AddRoster(rosterTwo, TeamRelation.enemy), "second roster not successfully added");
        }
示例#15
0
        internal static UnitBook GetLausUnits()
        {
            UnitBook ub = new UnitBook();

            //Enemy Units
            UnitEntity[] enemyUnits = new UnitEntity[4] {
                new FE7UnitEntity()
                {
                    InternalName   = "Erik",
                    InitalPosition = new Position(1, 10),
                    MaxHP          = 30,
                    Constitution   = 12,
                    Move           = 7,
                },
                new FE7UnitEntity()
                {
                    InternalName   = "Cavalier1",
                    InitalPosition = new Position(2, 9),
                    MaxHP          = 20,
                    Constitution   = 11,
                    Move           = 7,
                },
                new FE7UnitEntity()
                {
                    InternalName   = "Cavalier2",
                    InitalPosition = new Position(2, 8),
                    MaxHP          = 20,
                    Constitution   = 11,
                    Move           = 7,
                },
                new FE7UnitEntity()
                {
                    InternalName   = "EasternMerc",
                    InitalPosition = new Position(20, 16),
                    MaxHP          = 10,
                    Constitution   = 9,
                    Move           = 5,
                }
            };

            UnitRoster enemyRoster = new UnitRoster(enemyUnits, UnitTeam.team2);;

            //Player Units
            UnitEntity[] playerUnits = new UnitEntity[3] {
                new FE7UnitEntity()
                {
                    InternalName   = "Hector",
                    InitalPosition = new Position(20, 13),
                    Move           = 5,
                    MaxHP          = 20,
                    Constitution   = 15,
                    WeaponList     = new List <IWeaponItem>(new IWeaponItem[1]
                    {
                        new FE7Weapon()
                        {
                            Range = new List <int>(new int[1] {
                                1
                            }),
                            Weight     = 10,
                            Might      = 10,
                            Hit        = 75,
                            Crit       = 5,
                            WeaponType = FE7WeaponType.Axe,
                            Name       = "Wolf Beil",
                        }
                    })
                },
                new FE7UnitEntity()
                {
                    InternalName   = "Eliwood",
                    InitalPosition = new Position(20, 14),
                    Move           = 5,
                    MaxHP          = 20,
                    Constitution   = 12,
                    WeaponList     = new List <IWeaponItem>(new IWeaponItem[1]
                    {
                        new FE7Weapon()
                        {
                            Range = new List <int>(new int[1] {
                                1
                            }),
                            Weight     = 5,
                            Might      = 7,
                            Hit        = 95,
                            Crit       = 10,
                            WeaponType = FE7WeaponType.Sword,
                            Name       = "Rapier",
                        }
                    })
                },
                new FE7UnitEntity()
                {
                    InternalName   = "Serra",
                    InitalPosition = new Position(23, 11),
                    Move           = 5,
                    MaxHP          = 15,
                    Constitution   = 7,
                }
            };

            UnitRoster playerRoster = new UnitRoster(playerUnits, UnitTeam.team1);

            //team Erk
            UnitEntity[] erkUnits = new UnitEntity[1] {
                new FE7UnitEntity()
                {
                    InternalName   = "Erk",
                    InitalPosition = new Position(14, 15),
                    Move           = 7
                }
            };

            UnitRoster erkRoster = new UnitRoster(erkUnits, UnitTeam.team3);

            ub.AddRoster(enemyRoster, TeamRelation.enemy);
            ub.AddRoster(playerRoster, TeamRelation.player);
            ub.AddRoster(erkRoster, TeamRelation.ally);

            return(ub);
        }
示例#16
0
 //----------------------------------------------------------------------------------------------
 public void Awake()
 {
     UiController.Initialize();
     GameBoard.Initialize();
     UnitRoster.Initialize();
 }
示例#17
0
    //----------------------------------------------------------------------------------------------
    public void ExecuteTurn()
    {
        // select us
        UnitRoster.SelectUnit(unit);

        // verify we have at least 1 ai ability - if we don't, bail
        if (unit.UnitData.AiAbilities.Length == 0)
        {
            FinalizeTurn();
            return;
        }

        // choose a random ability
        AiAbility ability = unit.UnitData.AiAbilities[Random.Range(0, unit.UnitData.AiAbilities.Length - 1)];

        // find the best target
        switch (ability.TargetType)
        {
        case AiAbilityTargetType.ClosestThreat:
            // find the closest unit
            List <Tile> route;
            List <Tile> closestRoute = new List <Tile>();
            Tile        targetTile   = unit.Position[0]; // we have to init something - we change this soon

            foreach (Unit target in UnitRoster.Units)
            {
                if (target.UnitData.Owner != unit.UnitData.Owner)
                {
                    route = Pathfinder.GetBestRoute(unit, target, true);
                    Debug.Log("Distance to " + target.UnitData.DisplayName + ": " + route.Count);
                    if (closestRoute.Count == 0 || route.Count < closestRoute.Count)
                    {
                        closestRoute = route;
                        targetTile   = closestRoute[closestRoute.Count - 1];
                    }
                }
            }

            // the route currently includes the tiles occupied by the source and target units.
            // remove those to get the tiles we actually want to move along.
            closestRoute.RemoveAt(0);
            closestRoute.RemoveAt(closestRoute.Count - 1);

            // verify we found a target and it's actually in range - if not, bail
            if (closestRoute.Count > ability.MoveRange + unit.Body.GetInjuryModifiers(InjuryEffectType.MovementRange))
            {
                break;
            }

            // if we're not already adjacent to our target, move to them
            if (closestRoute.Count > 0)
            {
                UnitRoster.IssueSelectedUnitMoveOrder(closestRoute[closestRoute.Count - 1]);
            }

            // use the ability on the tile where our target is standing
            ability.Execute(targetTile);
            break;

        default:
            Debug.LogError("Unhandled ability target type '" + ability.TargetType + "'. Skipping turn.");
            break;
        }

        FinalizeTurn();
    }