Example #1
0
        public int SimToVictory(bool abortIfAnElfDies = false)
        {
            var round = 0;

            while (true)
            {
                if (DoRound(abortIfAnElfDies))
                {
                    if (abortIfAnElfDies && Elves.Any(e => e.IsDead))
                    {
                        return(-1);
                    }

                    if (Goblins.All(g => g.IsDead))
                    {
                        var hpLeft = Elves.Where(e => !e.IsDead).Sum(e => e.HP);
                        return(round * hpLeft);
                    }

                    if (Elves.All(e => e.IsDead))
                    {
                        var hpLeft = Goblins.Where(e => !e.IsDead).Sum(e => e.HP);
                        return(round * hpLeft);
                    }
                }

                round++;
            }
        }
Example #2
0
        private bool TryToFight(Elf elf)
        {
            var root      = new Coordinate(elf.X, elf.Y);
            var neighbors = GetNeighbors(root);

            var goblins = new List <Goblin>();

            foreach (var neighbor in neighbors)
            {
                var goblin = Goblins.Find(g => !g.IsDead && g.X == neighbor.X && g.Y == neighbor.Y);
                if (goblin != null)
                {
                    goblins.Add(goblin);
                }
            }

            var toAttack = goblins.OrderBy(g => g.HP).ThenBy(g => g.Y).ThenBy(g => g.X).FirstOrDefault();

            if (toAttack != null)
            {
                toAttack.HP -= elf.AP;

                if (toAttack.IsDead)
                {
                    Map[toAttack.X, toAttack.Y] = '.';
                }

                return(true);
            }

            return(false);
        }
Example #3
0
        public Goblin FindClosestEnemyTo(Elf source)
        {
            var sourceX = source.X;
            var sourceY = source.Y;

            var target = SearchFor('G', sourceX, sourceY);

            return(Goblins.Find(g => g.X == target.X && g.Y == target.Y));
        }
Example #4
0
    // Use this for initialization
    void Start()
    {
        GameState.InitializeState();

        Town[] towns = GameObject.FindObjectsOfType(typeof(Town)) as Town[];
        foreach (Town town in towns)
        {
            try {
                town.InitializeState();
            } catch {
                print("Couldn't find town with id: " + town.townId);
            }
        }

        List <Unit> units = new List <Unit>();

        // Initialize people
        foreach (GameState.PersonState state in GameState.personStates)
        {
            print("Loading " + state.id);
            Unit unit = (GameObject.Instantiate(this.unitPrefab, state.GetPosition(), Quaternion.identity) as GameObject).GetComponent <Unit>();
            unit.LoadState(state);
            units.Add(unit);
        }

        foreach (Unit unit in units)
        {
            if (unit.currentTown != null)
            {
                //unit.ArriveAtTown(unit.currentTown);
            }
        }

        //Initialize Goblins
        Goblins goblins = GameObject.FindObjectOfType(typeof(Goblins)) as Goblins;

        goblins.Initialize();

        //Initialize ring
        Ring ring = GameObject.FindObjectOfType(typeof(Ring)) as Ring;

        switch (GameState.ringState.locationType)
        {
        case GameState.RingState.LocationType.Town:
            Town town = Town.GetTown(GameState.ringState.location);
            ring.transform.position = town.transform.position;
            ring.PlaceInTown(town);
            break;

        case GameState.RingState.LocationType.Person:
            Unit unit = Unit.GetUnit(GameState.ringState.location);
            ring.transform.position = unit.transform.position;
            ring.GiveToPerson(unit);
            break;
        }
    }
Example #5
0
        public bool DoRound(bool abortIfAnElfDies = false)
        {
            var allFighters =
                Goblins.Cast <Fighter>()
                .Concat(Elves.Cast <Fighter>())
                .Where(f => !f.IsDead)
                .OrderBy(f => f.Y)
                .ThenBy(f => f.X).ToList();


            foreach (var fighter in allFighters)
            {
                if (Goblins.All(g => g.IsDead) || Elves.All(e => e.IsDead))
                {
                    return(true);
                }

                if (abortIfAnElfDies && Elves.Any(e => e.IsDead))
                {
                    return(true);
                }

                if (fighter.IsDead)
                {
                    continue;
                }

                if (fighter is Elf)
                {
                    var asElf = (Elf)fighter;

                    if (!TryToFight(asElf))
                    {
                        MoveToClosestEnemy(asElf);
                        TryToFight(asElf);
                    }
                }
                else
                {
                    var asGoblin = (Goblin)fighter;

                    if (!TryToFight(asGoblin))
                    {
                        MoveToClosestEnemy(asGoblin);
                        TryToFight(asGoblin);
                    }
                }
            }

            return(false);
        }
Example #6
0
 private void UpdateSoldierDefend()
 {
     if (this.targetTown == null)
     {
         Goblins goblins = GameObject.FindObjectOfType(typeof(Goblins)) as Goblins;
         if (goblins != null && !goblins.AreKilled() && goblins.targetTown != null)
         {
             Town town = goblins.targetTown;
             Dictionary <string, string> parameters = this.GetDialogParameters();
             parameters.Add("townName", town.townName);
             this.SetTargetTown(town);
         }
     }
 }
Example #7
0
    public static void Cleanup()
    {
        Unit[] units = GameObject.FindObjectsOfType(typeof(Unit)) as Unit[];
        foreach (Unit unit in units)
        {
            unit.CleanUp();
        }
        Town[] towns = GameObject.FindObjectsOfType(typeof(Town)) as Town[];
        foreach (Town town in towns)
        {
            town.Cleanup();
        }
        Goblins goblins = GameObject.FindObjectOfType(typeof(Goblins)) as Goblins;

        goblins.Cleanup();
    }
Example #8
0
    void OnMouseDown()
    {
        Light1.SetActive(true);
        Light2.SetActive(true);
        Light3.SetActive(false);
        Choose.isAim = false;

        for (int i = 0; i < 100; i++)
        {
            invipad[i].SetActive(false);
        }

        if (checkST == 0)
        {
            SingleATK.Single_ATK(vars, PlayerInfo.atk);
            PlayerInfo.attack = false;
        }

        else if (checkChar == 1)
        {
            if (checkST == 1)
            {
                Goblins.ACT_Skill_1(vars);
            }
        }

        else if (checkChar == 2)
        {
            if (checkST == 1)
            {
                Mermaids.ACT_Skill_1(vars);
            }

            else if (checkST == 2)
            {
                Mermaids.ACT_Skill_2(vars);
            }
        }

        else if (checkChar == 4)
        {
            if (checkST == 1)
            {
                Frankenstein.ACT_Skill_1(vars);
            }
        }
    }
Example #9
0
    void Update()
    {
        if (Input.GetKeyDown("g"))
        {
            print("Moving goblins");
            Goblins goblins = GameObject.FindObjectOfType(typeof(Goblins)) as Goblins;
            Town    town    = goblins.PickTown();
            goblins.SetTargetTown(town);
            goblins.SetKilled(false);
        }

        if (Input.GetKeyDown("s"))
        {
            print("Pronto!");
            DebugKeybindings.unitBaseSpeed = Unit.BASE_SPEED;
            Unit.BASE_SPEED *= 3.0f;
        }

        if (Input.GetKeyUp("s"))
        {
            print("Langsamer!");
            Unit.BASE_SPEED = DebugKeybindings.unitBaseSpeed;
        }

        if (Input.GetKeyUp("r"))
        {
            print("Ring");
            Unit bearer = Unit.GetUnit("adventurer");
            Ring ring   = GameObject.FindObjectOfType(typeof(Ring)) as Ring;
            ring.GiveToPerson(bearer);
        }

        if (Input.GetKeyUp("d"))
        {
            Door door = GameObject.FindObjectOfType(typeof(Door)) as Door;
            door.SetOpen(!door.isOpen);
            print(door.isOpen ? "opening door" : "closing door");
        }
    }
Example #10
0
    public void OnClick()
    {
        if (ConnectAndJoinRandom.character == 1)
        {
            Goblins.Skill_1();
        }

        else if (ConnectAndJoinRandom.character == 2)
        {
            Mermaids.Skill_1();
        }

        else if (ConnectAndJoinRandom.character == 3)
        {
            Griffon.Skill_1();
        }

        else if (ConnectAndJoinRandom.character == 4)
        {
            Frankenstein.Skill_1();
        }
    }
Example #11
0
    public void ArriveAtTown(Town town, bool isDestination)
    {
        if (this.type == Type.Bard && isDestination)
        {
            if (town.townId == "mission")
            {
                StartCoroutine("FadeOut");
                print("Available bards: " + string.Join(", ", GameState.availableBards.ToArray()));
            }
            else
            {
                town.ProcessStories(this.heardStories.ToArray());
                foreach (string storyId in town.folkSongs)
                {
                    if (!GameState.KnowsStory(storyId))
                    {
                        this.LearnStory(storyId);
                        this.ShowDialog("learn_folk_song");
                    }
                }
            }
        }

        if (this.type != Type.Bard && town.townId == "mission")
        {
            bool         learned    = false;
            List <Story> newStories = new List <Story>();
            foreach (Story story in this.heardStories)
            {
                if (!GameState.KnowsStory(story))
                {
                    learned = true;
                    GameState.AddKnownStory(story);
                    newStories.Add(story);
                }
            }
            if (learned)
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>()
                {
                    { "speakerId", this.state.id },
                    { "speakerName", this.state.name },
                    { "storyName", newStories[0].title }
                };
                GameState.ShowDialog("learn_from_unit", parameters);
            }
        }

        //TODO refactor
        Goblins goblins = GameObject.FindObjectOfType(typeof(Goblins)) as Goblins;

        if (goblins.targetTown == town && !goblins.AreKilled())
        {
            if (this.mode == Mode.SoldierDefend)
            {
                goblins.Kill();
                this.animator.SetTrigger("WarriorFight");
            }
            else
            {
                this.BeScaredByGoblins(town);
            }
        }

        if (this.mode == Mode.AdventurerRing)
        {
            if (Ring.IsAtTown(town))
            {
                Ring ring = GameObject.FindObjectOfType(typeof(Ring)) as Ring;
                this.ShowDialog("find_ring");
                ring.GiveToPerson(this);
            }
        }

        if (this.mode == Mode.AdventurerDeliver && Ring.BelongsTo(this) && town.townId == "fairy_castle")
        {
            this.ShowDialog("deliver_ring");
            Ring ring = GameObject.FindObjectOfType(typeof(Ring)) as Ring;
            ring.GiveToPerson(Unit.GetUnit("queen"));
            Door door = Town.GetTown("door_west") as Door;
            door.SetOpen(true);
        }
    }