Beispiel #1
0
        public IActionResult CreateManager([FromBody] ManagerInput requestDto)
        {
            _sessionService.CheckSession(GetToken(), GetCurrentUser());
            var data = _userService.CreateManager(new DataInput <ManagerInput>(requestDto, GetCurrentUser()));

            return(Json(data));
        }
Beispiel #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            _managerInput = new ManagerInput();


            base.Initialize();
        }
Beispiel #3
0
    /*
     * ExecHeal
     *
     * fuzzy function for healing the enemy that is closest and needs it the most
     *
     * @param BaseInput inp - the object containing useful data that the function uses to determine what to do
     * @returns void
     */
    public void ExecHeal(BaseInput inp)
    {
        //up-cast the base input
        ManagerInput minp = inp as ManagerInput;

        //don't do anything if the unit cannot attack
        if (minp.unit.hasAttacked)
        {
            return;
        }

        //get the size of the units
        int unitCount = units.Count;

        //track the lowest score of all units and the unit that gave the score
        Unit  highestUnit  = null;
        float highestScore = 0.0f;

        //iterate through all of the units, getting the lowest health ratio
        for (int i = 0; i < unitCount; i++)
        {
            //store in a temp value
            Unit unit = units[i];

            //inverse ratio of health remaining and the distance and calculate a score
            float healthRatio = 1 - unit.health / unit.maxHealth;
            float distance    = 1 - (Mathf.Abs(minp.unit.transform.position.x - unit.transform.position.x) + Mathf.Abs(minp.unit.transform.position.y - unit.transform.position.y));

            //higher scores if close or has little health
            float score = healthRatio * distance;

            //favour healing the king over other units
            if (unit is King)
            {
                score *= kingBias;
            }

            //compare with the lowest ratio and set it to that
            if (highestScore < score)
            {
                highestScore = score;
                highestUnit  = unit;
            }
        }

        //don't attempt to heal if there isn't a target to heal
        if (highestUnit != null)
        {
            ExecuteMovementGivenTarget(minp.unit, highestUnit.transform.position);

            //manhattan distance to the best healing target
            float manhatt = Mathf.Abs(minp.unit.transform.position.x - highestUnit.transform.position.x) + Mathf.Abs(minp.unit.transform.position.y - highestUnit.transform.position.y);

            //check that the unit is close enough to drop a special tile
            if (manhatt < minp.unit.attackRange)
            {
                Ability(minp.unit, highestUnit.transform.position);
            }
        }
    }
Beispiel #4
0
    /*
     * ExecGroup
     *
     * fuzzy function for regrouping the team
     *
     * @param BaseInput inp - the object containing useful data that the function uses to determine what to do
     * @returns void
     */
    public void ExecGroup(BaseInput inp)
    {
        //up-cast the base input
        ManagerInput minp = inp as ManagerInput;

        //don't do anything if the unit has run out of points
        if (minp.unit.movementPoints == 0)
        {
            return;
        }

        //get the length of the units list
        int unitCount = units.Count;

        //track the sum of all positions
        Vector3 sum = Vector3.zero;

        //get average position of the group
        for (int i = 0; i < unitCount; i++)
        {
            sum += units[i].transform.position;
        }

        //average group position
        Vector3 average = sum / unitCount;

        ExecuteMovementGivenTarget(minp.unit, average);
    }
Beispiel #5
0
    /*
     * EvalGroup
     *
     * fuzzy function used to determine if the group seeking function should be used
     *
     * @param BaseInput inp - the input of the fuzzy logic machine
     * @returns float - the score evaluated
     */
    public float EvalGroup(BaseInput inp)
    {
        //up-cast the base input
        ManagerInput minp = inp as ManagerInput;

        //get the length of the units list
        int unitCount = units.Count;

        //track the sum of all positions
        Vector3 sum = Vector3.zero;

        //get average position of the group
        for (int i = 0; i < unitCount; i++)
        {
            sum += units[i].transform.position;
        }

        //average group position
        Vector3 average = sum / unitCount;

        //get the maximum difference that the average position can possibly have from the unit
        float maxDifference = Mathf.Sqrt(map.mapTiles.Count);

        //relative vector from the unit to the average
        Vector3 relative = average - minp.unit.transform.position;

        //0 = at the centre of the group, 1 = maximum possible difference that can be achieved given the map size
        return((relative.magnitude / maxDifference) * groupImportance);
    }
Beispiel #6
0
    /*
     * EvalHeal
     *
     * fuzzy function used to determine if the unit should be healing
     *
     * @param BaseInput inp - the input of the fuzzy logic machine
     * @returns float - the score evaluated
     */
    public float EvalHeal(BaseInput inp)
    {
        //up-cast the base input
        ManagerInput minp = inp as ManagerInput;

        //don't even consider healing if the unit isn't a medic
        if (!(minp.unit is Medic))
        {
            return(0.0f);
        }

        //get the lowest health ratio
        float lowestRatio = 1.0f;

        //get the size of the units
        int unitCount = units.Count;

        //iterate through all of the units, getting the lowest health ratio
        for (int i = 0; i < unitCount; i++)
        {
            //store in a temp value
            Unit unit = units[i];

            //ratio of health remaining
            float healthRatio = unit.health / unit.maxHealth;

            //compare with the lowest ratio and set it to that
            if (healthRatio < lowestRatio)
            {
                lowestRatio = healthRatio;
            }
        }

        return(lowestRatio * healingImportance);
    }
Beispiel #7
0
    /*
     * EvalFlee
     *
     * fuzzy function used to determine if the player should run away
     *
     * @param BaseInput inp - the input of the fuzzy logic machine
     * @returns float - the score evaluated
     */
    public float EvalFlee(BaseInput inp)
    {
        //up-cast the base input
        ManagerInput minp = inp as ManagerInput;

        return((1 - (minp.unit.health / minp.unit.maxHealth)) * fleeImportance);
    }
Beispiel #8
0
 public ManagerReport(ManagerInput input)
     : this()
 {
     this.ManagerId   = input.Mid;
     this.ManagerName = input.Name;
     this.ManagerLogo = input.Logo;
     this.ClothId     = input.ClothId;
     this.FormId      = input.FormId;
 }
Beispiel #9
0
 public Game1()
     : base()
 {
     graphics = new GraphicsDeviceManager(this);
     Content.RootDirectory = "Content";
     _managerNetwork       = new ManagerNetwork();
     _managerInput         = new ManagerInput();
     _managerPlayers       = new ManagerPlayers(_managerNetwork);
     _managerEnemies       = new ManagerEnemies(_managerNetwork);
 }
        public ZeldaGame()
            : base()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            this.graphics.PreferredBackBufferHeight = 144;
            this.graphics.PreferredBackBufferWidth  = 160;
            _managerInput = new ManagerInput();
        }
        public Game1()
            : base()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            this.graphics.PreferredBackBufferHeight = 144;
            this.graphics.PreferredBackBufferWidth  = 160;
            _managerInput = new ManagerInput();
            Console.WriteLine("hej hej");
        }
Beispiel #12
0
        public static ManagerInput BuildTransferNpc(DicNpcEntity npcEntity, DTOBuffMemberView buffView)
        {
            var dstData = new ManagerInput();

            dstData.Mid    = npcEntity.Idx;
            dstData.Logo   = npcEntity.Logo.ToString();
            dstData.Name   = npcEntity.Name;
            dstData.FormId = npcEntity.FormationId;
            dstData.FormLv = npcEntity.FormationLevel;

            BuildManagerData(dstData, buffView, 0, npcEntity.Buff);
            return(dstData);
        }
Beispiel #13
0
    /*
     * UpdateTurn
     * overrides BasePlayers' UpdateTurn()
     *
     * called once per frame while the player is active
     *
     * @returns void
     */
    public override void UpdateTurn()
    {
        m_thinkTimer -= Time.deltaTime;

        //don't do anything if the think timer hasn't gone over the limit
        if (m_thinkTimer > 0.0f)
        {
            return;
        }

        //get the size of the units list
        int unitSize = units.Count;

        m_teamMember++;

        //reset the counter
        if (m_teamMember >= unitSize)
        {
            m_teamMember = 0;
        }

        //store in a temp value for readability
        Unit unit = units[m_teamMember];

        //up-cast the base input
        ManagerInput minput = logicMachine.input as ManagerInput;

        //set the correct unit in the input
        minput.unit = unit;

        //this will invoke the most appropriate callback
        logicMachine.Execute();

        if (IsBusy())
        {
            //reset the thinking timer
            m_thinkTimer = thinkTime;
        }
        else
        {
            //countdown the idle timer
            if (m_idleTimer > 0.0f)
            {
                m_idleTimer -= Time.deltaTime;
            }
            else
            {
                manager.OnNextTurn();
            }
        }
    }
Beispiel #14
0
        public static void BuildManagerData(ManagerInput dstData, DTOBuffMemberView buffView, int vipLevel, int buffScale, bool isGuide = false)
        {
            if (null == dstData)
            {
                return;
            }
            dstData.Players = new List <PlayerInput>(11);

            var legendCount = 0;

            foreach (var buffMember in buffView.BuffMembers.Values)
            {
                if (buffMember.IsMain)
                {
                    var cachePlayer = MatchDataUtil.GetDicPlayer(buffMember.Tid, buffMember.Pid);
                    if (cachePlayer.CardLevel == 2 || cachePlayer.CardLevel == 1 || cachePlayer.CardLevel == 7 || cachePlayer.CardLevel == 8)
                    {
                        legendCount++;
                    }
                }
            }
            buffScale += CacheFactory.AppsettingCache.GetSolutionLegendAndVipPlus(legendCount, vipLevel);
            double buffPlus = buffScale / 100.00;

            foreach (var buffMember in buffView.BuffMembers.Values)
            {
                if (buffMember.IsMain)
                {
                    var         cachePlayer          = MatchDataUtil.GetDicPlayer(buffMember.Tid, buffMember.Pid);
                    PlayerInput transferPlayerEntity = new PlayerInput();
                    transferPlayerEntity.FamilyName = cachePlayer.Name;
                    transferPlayerEntity.Height     = (int)cachePlayer.Stature;
                    transferPlayerEntity.Pid        = buffMember.Pid;
                    transferPlayerEntity.Plus       = (byte)buffMember.Strength;
                    transferPlayerEntity.Position   = (byte)buffMember.PPos;
                    BuildTeammemberData(transferPlayerEntity, buffMember, buffPlus, isGuide);
                    dstData.Players.Add(transferPlayerEntity);
                }
            }
            if (isGuide)
            {
                var list       = CacheFactory.NpcdicCache.GetGuidePlayers();
                int count      = list.Count;
                int totalCount = dstData.Players.Count;
                for (int i = 1; i <= count; i++)
                {
                    PlayerInputClone(dstData.Players[totalCount - i], list[i - 1]);
                }
            }
        }
Beispiel #15
0
	public void OnGlobalEnable()
	{
		_managerArray = this.GetComponent<ManagerArray>();
		_managerInput = this.GetComponent<ManagerInput>();
		_giveAllObjectsToManagers = GameObject.FindGameObjectWithTag("GiveAllObjectsToManagers").GetComponent<GiveAllObjectsToManagers>();

		_player = _giveAllObjectsToManagers.player;
		_elementMenuToShow = _giveAllObjectsToManagers.menuGame;
		_elementGameOverToShow = _giveAllObjectsToManagers.menuLoose;
		_elementWinToShow = _giveAllObjectsToManagers.menuWin;

		_displayMenuOnce = true;
		_canPause = true;
		_isOnGame = true;
	}
Beispiel #16
0
    /*
     * ExecAdvance
     *
     * fuzzy function for advancing the team to places that they havent explored
     *
     * @param BaseInput inp - the object containing useful data that the function uses to determine what to do
     * @returns void
     */
    public void ExecAdvance(BaseInput inp)
    {
        //up-cast the base input
        ManagerInput minp = inp as ManagerInput;

        //don't do anything if the unit has run out of points
        if (minp.unit.movementPoints == 0)
        {
            return;
        }

        //vector to the middle of the map
        Vector3 target = new Vector3(map.width, 0.0f, map.height) * 0.5f;

        ExecuteMovementGivenTarget(minp.unit, target);
    }
Beispiel #17
0
        public MyGame()
        {
            _graphics = new GraphicsDeviceManager(this);
            _graphics.PreferredBackBufferWidth  = 1366;
            _graphics.PreferredBackBufferHeight = 768;
            _graphics.ApplyChanges();

            Content.RootDirectory = "Content";

            _player        = new BaseObject();
            _pnj1          = new BaseObject();
            _enemy1        = new BaseObject();
            _managerInput  = new ManagerInput();
            _managerCamera = new ManagerCamera();
            _managerMap    = new ManagerMap("test", _managerCamera);
        }
Beispiel #18
0
    /*
     * EvalAttack
     *
     * fuzzy function used to determine if the attack function should be used
     *
     * @param BaseInput inp - the input of the fuzzy logic machine
     * @returns float - the score evaluated
     */
    public float EvalAttack(BaseInput inp)
    {
        //up-cast the base input
        ManagerInput minp = inp as ManagerInput;

        //don't even consider attacking if the unit is a medic
        if (minp.unit is Medic)
        {
            return(0.0f);
        }

        //count the visible and total enemies of the opponents
        int visibleEnemies = 0;
        int totalEnemies   = 0;

        //get the size of the players array
        int playerSize = minp.manager.players.Count;

        //iterate through all players except for this one, getting the amount of enemies that are visible and the total
        for (int i = 0; i < playerSize; i++)
        {
            //store in a temp variable
            BasePlayer bp = minp.manager.players[i];

            if (bp.playerID == playerID)
            {
                continue;
            }

            //get the size of the player's units array
            int unitCount = bp.units.Count;

            totalEnemies += unitCount;

            //check for visibility and count
            for (int j = 0; j < unitCount; j++)
            {
                if (bp.units[j].inSight)
                {
                    visibleEnemies++;
                }
            }
        }

        return(((float)visibleEnemies / (float)totalEnemies) * attackImportance);
    }
Beispiel #19
0
        public Game1()
            : base()
        {
            _managerInput         = new ManagerInput();
            graphics              = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            this.graphics.PreferredBackBufferHeight = 128;
            this.graphics.PreferredBackBufferWidth  = 160;

            _managerCamera = new ManagerCamera();

            _mainForm = new MainForm(_managerCamera);
            var thread = new Thread(new ThreadStart(new ThreadStart(RunGUI)));

            thread.Start();
        }
        public static ManagerInput BuildTransfer(LocalTransferManagerEntity localManager)
        {
            var buffView = GetMemberView(localManager);

            var dstData = new ManagerInput();

            dstData.Mid       = LocalHelper.BuildLocalManagerId(localManager.Id);
            dstData.Logo      = "1";
            dstData.Name      = localManager.Name;
            dstData.FormId    = localManager.FormationId;
            dstData.FormLv    = localManager.FormationLevel;
            dstData.Skills    = buffView.LiveSkillList;
            dstData.SubSkills = buffView.SubSkills;

            MatchTransferUtil.BuildManagerData(dstData, buffView, 0, 100);

            return(dstData);
        }
        public bool Start()
        {
            var random = new Random();
            NetPeerConfiguration config = new NetPeerConfiguration("ng");

            _client = new NetClient(config);
            _client.Start();
            Player = new Player("name_" + random.Next(0, 100), 0, 0);
            //Ground = new Platform()
            var outmsg = _client.CreateMessage();

            outmsg.Write((byte)PacketType.Login);
            outmsg.Write(Player.Name);
            _client.Connect("localhost", 63763, outmsg);
            _input = new ManagerInput(this);

            return(EsablishInfo());
        }
Beispiel #22
0
        static ManagerInput CreateTransferManagerArena(MatchManagerInfo managerInfo, DTOBuffMemberView buffView, bool isGuide, ArenaTeammemberFrame arenaFrame, string siteId = "")
        {
            if (null == buffView)
            {
                return(null);
            }
            var    manager  = MatchDataHelper.GetManager(managerInfo.ManagerId, false, false, siteId);
            var    solution = MatchDataHelper.GetArenaSolution(arenaFrame);
            string name     = managerInfo.IsBot ? _botName : manager.Name;

            managerInfo.Name = name;
            var dstData = new ManagerInput();

            dstData.Mid       = managerInfo.ManagerId;
            dstData.Name      = name;
            dstData.Logo      = manager.Logo.ToString();
            dstData.FormId    = solution.FormationId;
            dstData.FormLv    = solution.FormationLevel;
            dstData.ClothId   = buffView.ClothId;
            dstData.Skills    = buffView.LiveSkillList;
            dstData.SubSkills = buffView.SubSkills;
            if (null != buffView.MatchPropList)
            {
                dstData.PropList = new List <PropInput>();
                foreach (var item in buffView.MatchPropList)
                {
                    dstData.PropList.Add(new PropInput(item.Point, item.Percent, item.BuffId));
                }
            }
            if (null != buffView.MatchBoostList)
            {
                dstData.BoostList = new List <BoostInput>();
                foreach (var item in buffView.MatchBoostList)
                {
                    dstData.BoostList.Add(new BoostInput(item.BoostType, item.Point, item.Percent, item.BuffId));
                }
            }

            BuildManagerData(dstData, buffView, manager.VipLevel, managerInfo.BuffScale, isGuide);
            return(dstData);
        }
Beispiel #23
0
    private void Start()
    {
        managerinput = GetComponent <ManagerInput>();
        bicycle      = GetComponent <BicycleController>();
        isDebug      = true;
        ShowDebug(isDebug);

        if (managerinput.input_V == ManagerInput.Input_V.Arduino)
        {
            isArduino  = true;
            arduinoCom = FindObjectOfType <COM_Connection>();
            arduinoPort.transform.parent.gameObject.SetActive(true);
            arduinoString.transform.parent.gameObject.SetActive(true);
            arduinoPort.text = arduinoCom.portName;
        }
        else
        {
            arduinoPort.transform.parent.gameObject.SetActive(false);
            arduinoString.transform.parent.gameObject.SetActive(false);
        }
    }
Beispiel #24
0
        public static ManagerInput CreateDebugManager(bool homeFlag, Guid mid, int index, int formId, double propVal)
        {
            var obj = new ManagerInput();

            obj.Mid      = mid;
            obj.Kind     = 0;
            obj.Name     = "经理" + index;
            obj.Logo     = "Logo" + index;
            obj.ClothId  = 1;
            obj.FormId   = formId;
            obj.FormLv   = 9;
            obj.CoachId  = 1;
            obj.CoachLv  = 9;
            obj.BuffFact = 100;
            //obj.Skills = new string[] { "Test" }.ToList();
            //obj.SubSkills = new string[] { "Up,Down" };
            //obj.SubTactics = new string[] { "Up,Down" };
            if (homeFlag)
            {
                obj.Skills = new string[] { "X001_10", "X004_10" }
            }
Beispiel #25
0
        public void StartCutscene(CutScene.InGameCutsceneName name)
        {
            Debug.Log("Info: starting " + name + " cutscene.");

            // Subscribe the escape key so the player can escape the cutscene.
            ManagerInput.SubscribeButtonEvent(ManagerInput.ActionsLabels.Cancel, "Cancel", ManagerInput.EventTypeButton.Down, SkipCutscene);

            // Get the cutscene to play
            CutScene currentCutscene = cutscenes[name];

            if (currentCutscene != null)
            {
                // Subscribe to the end of the cutscene
                CutScene.OnCutsceneEnd += WhenCutsceneEnds;

                // Init it
                currentCutscene.Init();

                // Activate it
                Debug.Log("Info: activate " + name + " cutscene.");
                activeCutsceneName = name;
                currentCutscene.Activate();
            }
        }
Beispiel #26
0
 public void WhenCutsceneEnds(CutScene.InGameCutsceneName name)
 {
     // Unsubscribe the escape key so the player can escape the cutscene.
     ManagerInput.UnsubscribeButtonEvent(ManagerInput.ActionsLabels.Cancel);
     OnCutsceneHasEnded();
 }
Beispiel #27
0
	// I get the ball from the Resouces folder
	void Awake()
	{	
		_managerInput = GameObject.FindGameObjectWithTag("Manager").GetComponent<ManagerInput>();
		anim = GetComponent<Animator>();
	}
Beispiel #28
0
        public Manager(ManagerInput input, IMatch match, Side side)
        {
            if (input == null)
            {
                throw new ApplicationException("Initializes a new manager by null TransferManagerEntity.");
            }
            if (input.Players.Count == 0)
            {
                throw new ApplicationException("The manager has no team members. Manager name:" + input.Name);
            }
            if (input.Players.Count != Defines.Match.MAX_PLAYER_COUNT)
            {
                throw new ApplicationException("The manager's team members count is not 11. Manager name:" + input.Name + ", Team member count:" + input.Players.Count);
            }
            this._input      = input;
            this._match      = match;
            this._side       = side;
            this._status     = new ManagerStatus();
            this._report     = new ManagerReport(input);
            this._playerHash = new Dictionary <Position, List <IPlayer> >(4);
            _playerHash.Add(Position.Goalkeeper, new List <IPlayer>(8));
            _playerHash.Add(Position.Fullback, new List <IPlayer>(8));
            _playerHash.Add(Position.Midfielder, new List <IPlayer>(8));
            _playerHash.Add(Position.Forward, new List <IPlayer>(8));
            int formId   = input.FormId;
            var formCfg  = FormationCache.GetFormation(formId);
            int clientId = (_side == Side.Home) ? 0 : Defines.Match.MAX_PLAYER_COUNT;

            #region ISkill
            this.boostCore   = new BoostCore(match);
            this.buffCore    = new BuffCore(match);
            this.specBuffCoe = new SpecBuffCore();
            this.rootSkill   = new Skill(_match, this, string.Empty);
            #endregion

            PlayerInput pInput = null;
            Player      player = null;
            for (var i = 0; i < input.Players.Count; i++)
            {
                pInput = input.Players[i];
                var pForm = formCfg[i];
                pInput.Position = (byte)pForm.Position;
                player          = new Player(pInput, this, (byte)(i + clientId), pForm.Default, pForm.HalfDefault);
                _players.Add(player);
                _playerHash[pForm.Position].Add(player);
            }
            this.SkillPlayerList = new List <SkillEngine.SkillBase.Xtern.ISkillPlayer>(_players.Count);
            this.SkillPlayerList.AddRange(_players);

            #region Buff
            int last    = _match.RoundPerMinute * 90;
            int point   = 0;
            int percent = 0;
            if (null != input.PropList)
            {
                foreach (var item in input.PropList)
                {
                    if (null == item.BuffId)
                    {
                        continue;
                    }
                    point   = (int)(item.Point * 100);
                    percent = (int)(item.Percent * 10000);
                    this.AddBuff(CreatePropBuff(last, point, percent, item.BuffId));
                }
            }
            if (null != input.BoostList)
            {
                foreach (var item in input.BoostList)
                {
                    if (null == item.BuffId)
                    {
                        continue;
                    }
                    point   = (int)(item.Point * 100);
                    percent = (int)(item.Percent * 10000);
                    this.AddBoost(CreateBoostBuff(item.BoostType, last, point, percent, item.BuffId));
                }
            }
            #endregion
        }
Beispiel #29
0
    /*
     * ExecFlee
     *
     * fuzzy function for running away from less players
     *
     * @param BaseInput inp - the object containing useful data that the function uses to determine what to do
     * @returns void
     */
    public void ExecFlee(BaseInput inp)
    {
        //up-cast the base input
        ManagerInput minp = inp as ManagerInput;

        //get the size of the players array
        int playerSize = minp.manager.players.Count;

        //list of enemies that can be seen
        List <Unit> visibleEnemies = new List <Unit>();

        //iterate through all players except for this one, getting all of the visible enemies
        for (int i = 0; i < playerSize; i++)
        {
            //store in a temp variable
            BasePlayer bp = minp.manager.players[i];

            if (bp.playerID == playerID)
            {
                continue;
            }

            //get the size of the player's units array
            int unitCount = bp.units.Count;

            //check for visibility and count
            for (int j = 0; j < unitCount; j++)
            {
                if (bp.units[j].inSight)
                {
                    visibleEnemies.Add(bp.units[j]);
                }
            }
        }

        //get the size of the visible enemies list
        int visibleSize = visibleEnemies.Count;

        //cancel the movement if there are no enemies to run away from
        if (visibleSize == 0)
        {
            return;
        }

        //divide this to get the average
        Vector3 sum = Vector3.zero;

        //iterate through all of the units, adding them together
        for (int i = 0; i < visibleSize; i++)
        {
            //store in a temp variable
            Unit enemy = visibleEnemies[i];

            sum += enemy.transform.position;
        }

        //calculate the average from the sum and amount of additions to the sum
        Vector3 average = sum / visibleSize;

        //calculate a target away from the average
        Vector3 repel = minp.unit.transform.position + (minp.unit.transform.position - average);

        ExecuteMovementGivenTarget(minp.unit, repel);
    }
Beispiel #30
0
    /*
     * ExecAttack
     *
     * fuzzy function for attacking the enemy with the (most health x potential DPS)
     *
     * @param BaseInput inp - the object containing useful data that the function uses to determine what to do
     * @returns void
     */
    public void ExecAttack(BaseInput inp)
    {
        //up-cast the base input
        ManagerInput minp = inp as ManagerInput;

        //don't do anything if the unit cannot attack
        if (minp.unit.hasAttacked)
        {
            return;
        }

        //get a list of walkable tiles around the unit
        List <Tiles> attackable = GetArea.GetAreaOfAttack(map.GetTileAtPos(minp.unit.transform.position), minp.unit.attackRange, map);

        //worst possible score to start
        float bestScore = -1.0f;

        //reference to the best tile that has been found
        Tiles bestTile = null;

        //get the size of the walkable list
        int attackSize = attackable.Count;

        //iterate through all walkable tiles
        for (int i = 0; i < attackSize; i++)
        {
            //store in a temp variable
            Tiles tile = attackable[i];

            //does the tile contain an enemy
            if (tile.unit != null)
            {
                if (tile.unit.playerID != playerID)
                {
                    //health ratio * damage per turn / max health
                    float threatScore = (tile.unit.health / tile.unit.maxHealth) * tile.unit.damage / tile.unit.maxHealth;

                    if (bestScore < threatScore)
                    {
                        //reassign the best score
                        bestTile  = tile;
                        bestScore = threatScore;
                    }
                }
            }
        }

        //attack the best tile if one is found
        if (bestTile != null)
        {
            Attack(minp.unit, bestTile.pos);
        }
        else
        {
            //get the worst threat and move towards it
            Unit  bestTarget      = null;
            float bestThreatScore = -1.0f;

            //get the size of the players list
            int playerSize = minp.manager.players.Count;

            //iterate through all players except for this one, getting the average of all enemies
            for (int i = 0; i < playerSize; i++)
            {
                //store in a temp variable
                BasePlayer bp = minp.manager.players[i];

                if (bp.playerID == playerID)
                {
                    continue;
                }

                //get the size of the player's units array
                int unitCount = bp.units.Count;

                //check for visibility and count
                for (int j = 0; j < unitCount; j++)
                {
                    if (bp.units[j].inSight)
                    {
                        //store in a temp variable
                        Unit unit = bp.units[j];

                        //the unit is in sight, consider it a threat
                        float threatScore = (unit.health / unit.maxHealth) * unit.damage;

                        //reset the score
                        if (bestThreatScore < threatScore)
                        {
                            bestTarget      = unit;
                            bestThreatScore = threatScore;
                        }
                    }
                }
            }

            if (bestTarget != null)
            {
                //don't do anything if the unit has run out of points
                if (minp.unit.movementPoints == 0)
                {
                    return;
                }

                ExecuteMovementGivenTarget(minp.unit, bestTarget.transform.position);
            }
        }
    }