Example #1
0
 public void SpamFor(MobileAgent p, ushort count)
 {
     if (SpammerEnabled)
     {
         p.spammer += count;
     }
 }
Example #2
0
    public void OnStartSkill(NetworkMessage netMsg)
    {
        MObjects.StartSkill mObject = netMsg.ReadMessage <MObjects.StartSkill>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma == null)
        {
            return;
        }

        if (ma.isController)
        {
            if (mObject.skillType == 1) // area Spell
            {
                ma.castingItem.areaFollower = true;

                ParticleSystem.MainModule mm = areaFollower.indicator.main;
                mm.startSize = mObject.skillSize / 2;
            }
        }

        ma.lastSkill = mObject.skillId;
        ma.castingItem.StartCast(mObject.casttime, ma.skills[mObject.skillId], mObject.skillId);

        ma.Stop();
    }
Example #3
0
    public void OnSkillSpawn(NetworkMessage netMsg)
    {
        MObjects.SkillSpawn mObject = netMsg.ReadMessage <MObjects.SkillSpawn>();

        Skill s = Skill.list.Find(x => x.id == mObject.id);

        if (s == null)
        {
            Transform t     = skills.Find(x => x.name == mObject.clientPrefab);
            Transform skill = Instantiate(t, Vector3.zero, t.rotation);
            s           = skill.gameObject.AddComponent <Skill>();
            s.id        = mObject.id;
            s.offset    = t.position.y;
            s.moveSpeed = mObject.speed;
            s.casterId  = mObject.casterId;

            MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.casterId);
            if (ma != null)
            {
                mObject.position = ma.transform.position;
            }

            s.SetPosition(mObject.position);
            s.transform.eulerAngles = new Vector3(s.transform.eulerAngles.x, mObject.rotation, s.transform.eulerAngles.z);
        }
    }
Example #4
0
    public void OnAgentHealth(NetworkMessage netMsg)
    {
        MObjects.AgentHealth mObject = netMsg.ReadMessage <MObjects.AgentHealth>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma == null)
        {
            return;
        }

        if (mObject.hp < ma.currentHealth)
        {
            /*
             * GETHIT
             * */
            ma.CreateTextEffect((ma.currentHealth - mObject.hp).ToString(), Color.red);
        }

        ma.currentHealth = mObject.hp;

        ma.health.fillAmount = mObject.hp / (float)mObject.maxhp;

        if (!ma.isDead && ma.health.fillAmount <= 0)
        {
            CreateParticle("AgentDie", ma.transform);
        }

        ma.isDead = (ma.health.fillAmount <= 0);

        ma.healthText.text = mObject.hp + "/" + mObject.maxhp;
        ma.anim.SetBool("Dead", ma.isDead);
    }
Example #5
0
        public void BotRequest(int connectionId)
        {
            MobileAgent _ma = agents.Find(x => ((x.user != null) ? x.user.connectionId : x.customId) == connectionId);

            if (_ma != null && agents[0] == _ma && !isStarted && canAddBots && agents.Count < MapLoader.maps[map].minPlayers && agents.FindAll(x => x.heroType == HeroType.Player).Count < MapLoader.maps[_ma.session.map].maxPlayers && !killed)
            {
                AISpawner.SpawnPlayerBot(ServerManager.playerHeroes [Random.Range(0, ServerManager.playerHeroes.Count)].clientPrefab, this);
            }
        }
Example #6
0
        public void SkillRequest(int connectionId, ushort skillId)
        {
            MobileAgent _ma = agents.Find(x => ((x.user != null) ? x.user.connectionId : x.customId) == connectionId);

            if (_ma != null && !_ma.isDead && _ma.skillStart == 0f)
            {
                SpamController.obj.SpamFor(_ma, 3);

                _ma.SkillRequest(skillId);
            }
        }
Example #7
0
    public void OnAgentDestroy(NetworkMessage netMsg)
    {
        MObjects.AgentDestroy mObject = netMsg.ReadMessage <MObjects.AgentDestroy>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma != null)
        {
            Destroy(ma.gameObject);
        }
    }
Example #8
0
        public void AimAgent(int connectionId, Vector3 y, Vector3 agentPos)
        {
            MobileAgent _ma = agents.Find(x => ((x.user != null) ? x.user.connectionId : x.customId) == connectionId);

            if (_ma != null && !_ma.isDead)
            {
                SpamController.obj.SpamFor(_ma, 1); // client can send this per 0.05f seconds or the spammer will be increased

                _ma.Aim(y, agentPos);
            }
        }
Example #9
0
    public static MobileAgent SpawnPlayerBot(string clientPrefab, Callipso.GameSession session)
    {
        MobileAgent created = ServerManager.current.JoinGame(null, session, _botNames.list [Random.Range(0, _botNames.list.Count)], null, true);
        AIAgent     ai      = created.gameObject.AddComponent <AIAgent>();

        ai.agent     = created;
        ai.vision    = 20;
        created.user = null;

        return(created);
    }
Example #10
0
        public short GetBuffEffect(MobileAgent agent)
        {
            switch (buffType)
            {
            case buffTypes.DamagerObject:
            case buffTypes.DamageShield:
                return((short)Mathf.Round(agent.skills[0].GetEffect(agent) * buffEffect / 100f));

            default:
                return(buffEffect);
            }
        }
Example #11
0
    private void Start()
    {
        if (to == null)
        {
            to = MobileAgent.list.Find(x => x.id == GetComponent <Skill>().casterId);
        }

        if (to != null && from != null) // It's an after effect
        {
            Destroy(gameObject, 0.5f);  // destroy after 0.6 sec
        }
    }
Example #12
0
    public static MobileAgent SpawnCreature(string clientPrefab, Callipso.GameSession session)
    {
        Callipso.Hero creature = ServerManager.creatureHeroes.Find(x => x.clientPrefab == clientPrefab);
        MobileAgent   created  = ServerManager.current.JoinGame(null, session, creature.alias, clientPrefab);
        AIAgent       ai       = created.gameObject.AddComponent <AIAgent>();

        ai.agent     = created;
        ai.vision    = creature.vision; // Bots always can see
        created.user = null;

        return(created);
    }
Example #13
0
    public void OnAgentStop(NetworkMessage netMsg)
    {
        MObjects.AgentStop mObject = netMsg.ReadMessage <MObjects.AgentStop>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma == null || (ma.isController && !mObject.includeClient))
        {
            return;
        }

        ma.Stop();
    }
Example #14
0
    public void OnAgentMove(NetworkMessage netMsg)
    {
        MObjects.AgentMove mObject = netMsg.ReadMessage <MObjects.AgentMove>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma == null || ma.isController)
        {
            return;
        }

        ma.StartMove(mObject.value);
    }
Example #15
0
    public void OnEndSkill(NetworkMessage netMsg)
    {
        MObjects.EndSkill mObject = netMsg.ReadMessage <MObjects.EndSkill>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma == null)
        {
            return;
        }

        ma.anim.SetTrigger("Skill" + ma.lastSkill);
        ma.castingItem.FinishCast();
    }
Example #16
0
    public void OnHook(NetworkMessage netMsg)
    {
        MObjects.Hook mObject = netMsg.ReadMessage <MObjects.Hook>();
        MobileAgent   from    = MobileAgent.list.Find(x => x.id == mObject.from);
        MobileAgent   to      = MobileAgent.list.Find(x => x.id == mObject.to);

        HookScript hs = Instantiate(hookEffect, to.transform.position, Quaternion.LookRotation(from.transform.position - to.transform.position)).GetComponent <HookScript>();

        hs.to   = to;
        hs.from = from;

        /*
         * MOVE FROM TO TO
         * */
    }
Example #17
0
        public void MoveAgent(int connectionId, Vector3 tPos)
        {
            MobileAgent _ma = agents.Find(x => ((x.user != null) ? x.user.connectionId : x.customId) == connectionId);

            if (_ma != null && _ma.skillStart < Time.time && !_ma.isDead)
            {
                SpamController.obj.SpamFor(_ma, 1); // client can send this per 0.05f seconds or the spammer will be increased

                if (MapLoader.isBlocked(map, _ma.transform.position, tPos, false))
                {
                    tPos = MapLoader.latestPoint(map, _ma.transform.position, tPos);
                }

                _ma.targetPoint = tPos;
            }
        }
Example #18
0
    public void OnAgentAim(NetworkMessage netMsg)
    {
        MObjects.AgentAim mObject = netMsg.ReadMessage <MObjects.AgentAim>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma == null)
        {
            return;
        }

        if (!ma.isController)
        {
            ma.aimPoint = mObject.y;
        }
    }
Example #19
0
    public void OnTeleport(NetworkMessage netMsg)
    {
        MObjects.Teleport mObject = netMsg.ReadMessage <MObjects.Teleport>();
        MobileAgent       ma      = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma != null)
        {
            mObject.pos.y         = MapLoader.GetHeight(mObject.pos);
            ma.transform.position = mObject.pos;

            /*
             * TELEPORT EFFECT
             * */

            CreateParticle("Teleport", ma.transform);
        }
    }
Example #20
0
    public void OnAgentInfo(NetworkMessage netMsg)
    {
        MObjects.AgentInfo mObject = netMsg.ReadMessage <MObjects.AgentInfo>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma == null) // Create the agent.
        {
            ma = CreateAgent(mObject);
        }
        else if (mObject.clientPrefab != ma.clientPrefab)
        {
            Destroy(ma.gameObject);
            ma = CreateAgent(mObject);
        }

        ma.moveSpeed = mObject.moveSpeed;
    }
Example #21
0
    public void OnSyncPosition(NetworkMessage netMsg)
    {
        MObjects.SyncPosition mObject = netMsg.ReadMessage <MObjects.SyncPosition>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma == null)
        {
            return;
        }

        mObject.pos.y = MapLoader.GetHeight(mObject.pos);

        float distance = GetDistance(ma.transform.position, mObject.pos);

        if (distance > ((ma.isController) ? 2 : 0.5f))
        {
            ma.Fix(mObject.pos);
        }
    }
        /// <summary>
        /// Using a list of agents, this method returns the agent which is located closest (by manhatten distance) to the passed mobile agent.
        /// </summary>
        /// <returns>The closest agent by type.</returns>
        /// <param name="mobileAgent">Mobile agent.</param>
        /// <param name="agentsToCheck">Agents to check.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        private T GetClosestAgentByType <T>(MobileAgent mobileAgent, IEnumerable <T> agentsToCheck)
            where T : Agent
        {
            if (mobileAgent == null)
            {
                throw new ArgumentNullException("mobileAgent");
            }

            if (agentsToCheck.Count() > 0)
            {
                // calculate the closest snack machine's manhatten distance
                int minimumDistance = Int32.MaxValue;
                T   closestAgent    = null;

                foreach (var agentToCheck in agentsToCheck)
                {
                    // we want to remove assigned office desks from the list of closest agents because they should be considered taken, so skip over them
                    if (agentToCheck is OfficeDesk)
                    {
                        var officeDesk = agentToCheck as OfficeDesk;
                        if (officeDesk.IsAssignedToAnEmployee)
                        {
                            continue;
                        }
                    }

                    // TODO: rethink this? we are looking up the best path in an inefficient way
                    var bestPath = GetBestPathToAgent(mobileAgent, agentToCheck);

                    if (bestPath.Count < minimumDistance)
                    {
                        minimumDistance = bestPath.Count;
                        closestAgent    = agentToCheck;
                    }
                }

                return(closestAgent);
            }

            return(null);
        }
        /// <summary>
        /// Adds and intention based on the passed intention type to the from agent based on the passed to agent. Basically, the "fromAgent"
        /// will perform whatever intention is indicated by the "intentionType" on the "toAgent", such as walking to a snack machine to drink.
        /// </summary>
        /// <param name="fromAgent">From agent.</param>
        /// <param name="toAgent">To agent.</param>
        /// <param name="intentionType">Intention type.</param>
        private void AddIntentionToAgent(MobileAgent fromAgent, Agent toAgent, IntentionType intentionType)
        {
            Agent walkFromAgent;

            Intention finalIntention = fromAgent.FinalIntention;

            // if we have a final intention currently queued up, then we want to calculate the path from that position
            if (finalIntention != null)
            {
                walkFromAgent = finalIntention.WalkToAgent;
            }
            // otherwise, we want to calculate the path from our current position
            else
            {
                walkFromAgent = fromAgent;
            }

            var bestPathToClosestAgent = GetBestPathToAgent(walkFromAgent, toAgent);

            fromAgent.AddIntention(new Intention(toAgent, bestPathToClosestAgent, intentionType));
        }
Example #24
0
        public ushort KickPlayer(int connectionId)
        {
            Debug.Log("Player is removing from the session");
            MobileAgent _ma = agents.Find(x => ((x.user != null) ? x.user.connectionId : x.customId) == connectionId);

            ushort savedSpam = _ma.spammer;

            Object.Destroy(_ma.gameObject);
            agents.Remove(_ma);

            if (agents.FindAll(x => x.user != null).Count == 0)
            {
                Kill();
                ServerManager.sessions.Remove(this); //Close session immediately
            }
            else
            {
                Update();
            }

            return(savedSpam);
        }
Example #25
0
    public void OnSkillEffect(NetworkMessage netMsg)
    {
        MObjects.SkillEffect mObject = netMsg.ReadMessage <MObjects.SkillEffect>();

        MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma == null)
        {
            return;
        }

        Transform t = skillEffect.Find(x => x.name == mObject.clientPrefab);

        if (t == null)
        {
            return;
        }
        Transform created = Instantiate(t, ma.transform.position + new Vector3(0, t.position.y, 0), t.rotation);

        created.gameObject.AddComponent <ParticleFollow>().target = ma.transform;
        Destroy(created.gameObject, 5);
    }
Example #26
0
        public void HeroChange(int connectionId, ushort val)
        {
            MobileAgent _ma = agents.Find(x => ((x.user != null) ? x.user.connectionId : x.customId) == connectionId);

            if (_ma != null)
            {
                if (val < 0 || val >= ServerManager.playerHeroes.Count || isStarted)
                {
                    return;
                }

                /*
                 * IF YOU WANT TO MAKE SOME 'UNLOCK HEROES' THING. THIS IS THE PLACE
                 * */

                _ma.LoadHero(ServerManager.playerHeroes[val].clientPrefab, true);

                Update(true);

                _ma.agentLevel.UpdateLevel();
            }
        }
Example #27
0
    public void OnKillInfo(NetworkMessage netMsg)
    {
        MObjects.KillInfo mObject = netMsg.ReadMessage <MObjects.KillInfo>();

        MobileAgent ma_killed = MobileAgent.list.Find(x => x.id == mObject.tId);
        MobileAgent ma_died   = MobileAgent.list.Find(x => x.id == mObject.id);

        if (ma_died.isCreature || ma_killed.isCreature)
        {
            return; // Not for creatures
        }
        Transform t = Instantiate(killInfo_Prefab, killInfo_Grid);

        Color tColor = (ma_died.team == MobileAgent.user.team) ? Color.red : Color.green;

        tColor.a = 0.5f;
        t.GetComponent <Image>().color = tColor;
        t.Find("diedIcon").GetComponent <Image>().sprite   = icons.Find(x => x.name == ma_died.clientPrefab);
        t.Find("killerIcon").GetComponent <Image>().sprite = icons.Find(x => x.name == ma_killed.clientPrefab);
        t.Find("diedAlias").GetComponent <Text>().text     = ma_died.alias;
        t.Find("killerAlias").GetComponent <Text>().text   = ma_killed.alias;
    }
Example #28
0
    void GetSupport()
    {
        if (skills_defense.Length == 0)
        {
            return;
        }

        MobileAgent ally = agent.session.agents.Find(x => (x == agent || (x.team == agent.team && agent.session.teamsize != 0)) && !x.isDead && x.health < x.maxHealth / 2 && (x == agent || PhysikEngine.GetDistance(x.transform.position, agent.transform.position) <= 20));

        if (ally == null)
        {
            return;
        }

        if (ally != agent && agent.session.teamsize == 0)
        {
            ally = agent;
        }

        if (ally == agent || !MapLoader.isBlocked(agent.session.map, transform.position, ally.transform.position, false)) // TARGET IN SIGHT
        {
            short tSpell = -1;

            /*
             * DECIDE WITH PROPORTION RANDOM
             * */
            /*
             * */

            ProportionValue <ushort>[] clist = new ProportionValue <ushort> [skills_defense.Length];

            ushort rVal = (ushort)clist.Length;

            for (ushort r = 0; r < rVal; r++)
            {
                ushort idx = (ushort)agent.skills.ToList().FindIndex(x => x == skills_defense[r]);
                clist[r] = ProportionValue.Create((agent.cooldowns[idx] < Time.time) ? agent.skills[idx].botsDecideChance : 1, idx);
            }

            if (rVal > 1)
            {
                rVal = clist.ChooseByRandom();
            }
            else
            {
                rVal = clist[0].Value;
            }

            float distance = (agent.skills[rVal].skillType == SkillType.Area) ? 10 : (agent.skills[rVal].moveSpeed * agent.skills[rVal].life);

            if ((distance * 3) / 4 > distanceToActive)
            {
                tSpell = (short)rVal;
            }

            if (tSpell != -1)
            {
                /*
                 * CAST SPELL
                 * */
                agent.session.LastAim(agent.customId, ally.transform.position, transform.position);
                agent.session.SkillRequest(agent.customId, (ushort)tSpell);
                return;
            }
        }
        //
    }
        /// <summary>
        /// Walks the passed mobile agent to the closest agent of type T.
        /// </summary>
        /// <param name="agent">Agent.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public void WalkMobileAgentToClosest <T>(MobileAgent mobileAgent)
            where T : Agent
        {
            IntentionType intentionType = IntentionType.Unknown;

            if (typeof(T) == typeof(SodaMachine))
            {
                intentionType = IntentionType.BuyDrink;
            }
            else if (typeof(T) == typeof(SnackMachine))
            {
                intentionType = IntentionType.BuySnack;
            }
            else if (typeof(T) == typeof(OfficeDesk))
            {
                intentionType = IntentionType.GoToDesk;
            }

            // if we don't already intend to perform that intention, proceed
            if (mobileAgent.IsAlreadyIntention(intentionType))
            {
                return;
            }

            var agentsToCheck = GetTrackedAgentsByType <T>();

            // if there are agents by that type to head towards, proceed
            if (agentsToCheck.Count() == 0)
            {
                return;
            }

            // find the closest agent by the type T to the employee and set the employee on his way towards that agent if any exists
            var closestAgent = GetClosestAgentByType(mobileAgent, agentsToCheck);

            // if there is an actual closest agent in the simulation, proceed
            if (closestAgent == null)
            {
                return;
            }

            // if this is a triggerable, subscribe to the trigger now that we intend to go to it
            //						if (closestAgent is ITriggerable)
            //						{
            //							var triggerable = closestAgent as ITriggerable;
            //							if (closestAgent is SodaMachine)
            //								triggerable.Trigger.AddSubscriptionToActionByType(mobileAgent, SubscriptionType.Once, ActionType.DispenseDrink);
            //							if (closestAgent is SnackMachine)
            //								triggerable.Trigger.AddSubscriptionToActionByType(mobileAgent, SubscriptionType.Once, ActionType.DispenseFood);
            //						}

            // we only want to add a "go to office desk" intention if the desk is not assigned to someone
            if (closestAgent is OfficeDesk)
            {
                var closestOfficeDesk = closestAgent as OfficeDesk;
                if (!closestOfficeDesk.IsAssignedToAnEmployee)
                {
                    AddIntentionToAgent(mobileAgent, closestAgent, intentionType);
                }
            }
            else
            {
                AddIntentionToAgent(mobileAgent, closestAgent, intentionType);
            }
        }
Example #30
0
    void Update()
    {
        if (myAgent.isController && !GameManager.SessionEnd && GameManager.sessionStarted)
        { // only if this is the controller one
            TryToMove();
        }

        if (autoTarget != null)
        {
            AutoTarget.singleton.icon.transform.position = Camera.main.WorldToScreenPoint(autoTarget.transform.position);
        }

        if (nextAuto > Time.time)
        {
            return;
        }

        nextAuto = Time.time + 0.1f;

        if (autoTargeter)
        {
            /*
             * MOVE TO TARGET
             * */

            if (autoTarget != null && (MapLoader.isBlocked(GameManager.currentMapId, transform.position, autoTarget.transform.position, false) || autoTarget.currentHealth == 0))
            {
                autoTarget = null;
                nextTarget = 0;
            }

            if (nextTarget < Time.time && autoTarget == null)
            {
                nextTarget = Time.time + 2; // Search for target per 4 seconds

                List <MobileAgent> possibleTargets = MobileAgent.list.FindAll(x => (x.team != myAgent.team || GameManager.singleton.sessionUpdate.teamSize == 0) && x.currentHealth > 0 && !MapLoader.isBlocked(GameManager.currentMapId, myAgent.transform.position, x.transform.position, false));
                possibleTargets = possibleTargets.OrderBy(x => GameManager.GetDistance(x.transform.position, myAgent.transform.position)).ToList();

                if (possibleTargets.Count > 0)
                {
                    autoTarget    = possibleTargets[0];
                    targetSkill   = GameManager.singleton.skillsHolder.GetChild(0).GetComponent <UISkillItem>(); // First skill
                    skillDistance = targetSkill.skillInfo.life * targetSkill.skillInfo.moveSpeed;                // First skill's distance
                }
                else
                {
                    autoTargeter = false; // Disable auto targeting
                    return;
                }
            }

            /*
             * GOTO TARGET
             * */
            if (autoTarget != null)
            {
                float dist = GameManager.GetDistance(myAgent.transform.position, autoTarget.transform.position);
                if (dist < skillDistance / 1.25f)
                {
                    if (GameManager.singleton.skillsHolder.GetChild(0).GetComponentInChildren <Filler>()._image.fillAmount == 0)
                    {
                        if (myAgent.isCasting)
                        {
                            AimRequest(autoTarget.transform.position);
                        }
                        targetSkill.Request();
                    }
                    else
                    {
                        MoveRequest(transform.position, true);
                    }
                }
                else if (dist > skillDistance)
                {
                    MoveRequest(autoTarget.transform.position);
                }
            }
        }
    }