Ejemplo n.º 1
0
 private void Start()
 {
     _rigidbody      = GetComponent <Rigidbody2D>();
     _botBehaviour   = GetComponent <BotBehaviour>();
     _spriteRenderer = GetComponent <SpriteRenderer>();
     onMyTurn       += SetMove;
 }
Ejemplo n.º 2
0
        void Conquest(Country country, BotBehaviour behaviour)
        {
            var totalArmy     = _army.GetTotalCount(country);
            var availableArmy = _army.GetAvailableCount(country);
            var canBeUsedArmy = (int)Math.Ceiling(availableArmy - totalArmy * (1 - behaviour.Aggressive));

            if (canBeUsedArmy > 0)
            {
                Debug.WriteLine(
                    $"BotController ({country}).Conquest: Can send {canBeUsedArmy} soldiers (available = {availableArmy}, total = {totalArmy})"
                    );
                var acceptableLocs = _conquest.GetAcceptableLocations(country);
                if (acceptableLocs.Count > 0)
                {
                    var selectedLocs = acceptableLocs;
                    var squadSize    = Math.Max(canBeUsedArmy / selectedLocs.Count, GetMinSquadSize(country));
                    Debug.WriteLine(
                        $"BotController ({country}).Conquest: Squad size = {squadSize}, " +
                        $"locations = (all = {acceptableLocs.Count}, selected = {selectedLocs.Count})"
                        );
                    foreach (var loc in selectedLocs)
                    {
                        var homeLoc   = loc.Item1;
                        var targetLoc = loc.Item2;
                        var maxCount  = _army.GetAvailableCount(country);
                        if (maxCount > 0)
                        {
                            var curCount = Math.Min(squadSize, maxCount);
                            var squad    = _army.TryAquireSquad(country, curCount);
                            _conquest.StartConquest(country, squad, homeLoc, targetLoc, (r, _) => OnConquestComplete(r));
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static MoveContoller Create(BotBehaviour owner)
        {
            MoveContoller retMe = new MoveContoller();

            retMe.OnInit();
            retMe.Owner     = owner;
            retMe.transform = owner.transform;
            return(retMe);
        }
Ejemplo n.º 4
0
 public override void Click(PlayerController pC)
 {
     BotBehaviour.SetDifficulty(difficulty);
     GameObject[] g = GameObject.FindGameObjectsWithTag("Sign");
     for (int i = 0; i < g.Length; i++)
     {
         if (g[i].GetComponent <DifficultySign>() != null)
         {
             g[i].transform.GetChild(0).gameObject.GetComponent <TextMesh>().color = new Color(0.0f, 0.0f, 0.0f);
         }
     }
     transform.GetChild(0).gameObject.GetComponent <TextMesh>().color = new Color(1.0f, 0.0f, 0.0f);
 }
Ejemplo n.º 5
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (BotBehaviour.Start())
     {
         Text                        = BotBehaviour.me.Username;
         label2.Text                 = "работает";
         button1.Enabled             = false;
         BotBehaviour.Bot.OnMessage += BotOnMessageReceived;
     }
     else
     {
         MessageBox.Show("Не удалось запустить бота");
     }
 }
Ejemplo n.º 6
0
        void Recruit(Country country, BotBehaviour behaviour)
        {
            var prevDate             = Date.PrevDay(_time.CurDate);
            var income               = _money.GetIncome(country, prevDate).Sum(it => it.Gold.Value);
            var expenses             = _army.GetTotalUsage(country).Value;
            var availableMoneyPerDay = income - expenses;
            var soldierUsage         = _army.GetUsagePerSoldier(country).Value;
            var newArmyCount         = availableMoneyPerDay / soldierUsage - 1;

            if (newArmyCount > 0)
            {
                Debug.WriteLine($"BotController ({country}).Recruit: {newArmyCount} soldiers");
                _army.Recruit(country, newArmyCount);
            }
        }
        void CheckForNearbyBots()
        {
            bool wasFiringBefore = (targettedBot != null);

            foreach (KeyValuePair <string, BotBehaviour> bb in rb.botTable)
            {
                if (IsPosInRange(bb.Value.transform.position))
                {
                    targettedBot = bb.Value;
                }
            }
            if (wasFiringBefore && targettedBot == null)
            {
                StopFire();
            }
            else if (!wasFiringBefore && targettedBot != null)
            {
                StartFire(targettedBot.transform.position);
            }
        }
Ejemplo n.º 8
0
 public void SetOwner(BotBehaviour owner)
 {
     Owner = owner;
 }
Ejemplo n.º 9
0
 public void RegisterBehaviour(Action <GameMaster, Bot> registerAction, BotBehaviour behaviour)
 {
     this.behaviour = behaviour;
     registerAction.Invoke(this.master, this);
 }
Ejemplo n.º 10
0
 private void Main_FormClosing(object sender, FormClosingEventArgs e)
 {
     BotBehaviour.Stop();
     Application.Exit();
 }
Ejemplo n.º 11
0
 public BotModule(SkryptEngine engine, BotBehaviour botBehaviour) : base(engine)
 {
     _botBehaviour = botBehaviour;
 }
Ejemplo n.º 12
0
    //Create bots
    public bool Init(string[] teamNames, RoundMaster round)
    {
        this.master = round;

        // create rockets
        this.rockets = new RocketPool();
        this.rockets.InitPool(this.rocketSettings.RockePoolNumber, this.rocketSettings.RocketPrefab);

        // create teams
        this.teams = new Team[teamNames.Length];
        for (int i = 0; i < this.teams.Length; i++)
        {
            GameObject team_root = Instantiate(this.gameSettings.Teamprefab, Vector3.zero, Quaternion.identity);
            team_root.name = "TEAM_" + teamNames[i];

            this.teams[i]            = team_root.GetComponent <Team>();
            this.teams[i].team_color = team_color[i];
            this.teams[i].layer      = LayerMask.NameToLayer(layers[i]);
        }

        for (int i = 0; i < this.teams.Length; i++)
        {
            this.teams[i].Init(this, i);
            this.teams[i].SetPositions(this.teamPlaces[i]);
        }


        // create bots
        bots = new Bot[this.teamSettings.BotNumber * 2];
        for (int i = 0; i < this.teams.Length; i++)
        {
            teams[i].bots = new Bot[this.teamSettings.BotNumber];
            for (int j = 0; j < this.teamSettings.BotNumber; j++)
            {
                GameObject bot_go = (GameObject)GameObject.Instantiate(this.gameSettings.BotPrefab, this.teams[i].Places.GetPlacePosition(KeyPlaces.SPAWN),
                                                                       Quaternion.identity);
                bot_go.GetComponent <Renderer>().material.color = team_color[i];
                bot_go.layer            = teams[i].layer;
                bot_go.transform.parent = this.teams[i].transform;
                bot_go.name             = "bot-" + j + "_team-" + i;

                Bot bot_infos = bot_go.GetComponent <Bot>();
                bot_infos.Init(j * HASH_MULTIPLICATOR + i, this);


                teams[i].bots[j] = bot_infos;
                bots[i * this.teamSettings.BotNumber + j] = bot_infos;
            }
        }

        // register behaviour
        for (int i = 0; i < this.teams.Length; i++)
        {
            // team behaviour
            string team_script = FindScriptContainingWords(teamNames[i], "team");
            if (team_script == "")
            {
                return(false);
            }

            this.teams[i].gameObject.AddComponent(System.Type.GetType(team_script));
            var teamBehaviour = this.teams[i].GetComponent <TeamBehaviour>();
            this.teams[i].RegisterBehaviour(teamBehaviour.Init, teamBehaviour);

            // bots behaviour
            string bot_script = FindScriptContainingWords(teamNames[i], "bot");
            if (bot_script == "")
            {
                return(false);
            }
            for (int j = 0; j < this.teams[i].bots.Length; j++)
            {
                this.teams[i].bots[j].gameObject.AddComponent(System.Type.GetType(bot_script));
                BotBehaviour behaviour = this.teams[i].bots[j].GetComponent <BotBehaviour>();
                this.teams[i].bots[j].RegisterBehaviour(behaviour.Init, behaviour);
            }

            teamBehaviour.RegisterBot(this.teams[i].bots);
        }

        // create flags
        this.flags = new Flag[2];
        for (int i = 0; i < this.teams.Length; i++)
        {
            var        index  = i;
            GameObject flagGo = Instantiate(this.gameSettings.FlagPrefab) as GameObject;
            flags[i]      = flagGo.GetComponent <Flag>();
            flags[i].name = "flag_" + i;
            flags[i].tag  = "Flag";
            flags[i].GetComponent <Renderer>().material.color = team_color[i];
            this.teams[index].SetFlag(flags[index]);
            flags[i].Init(this, this.teams[i]);
            flags[i].Disable();
        }

        respawnList = new List <RespawnData>();

        return(true);
    }