示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (!agent.session.isStarted || agent.session.killed)
        {
            return;
        }

        if (activeTarget != null && agent.skillStart != 0f)
        { // If there is target and this is on skill casting, always keep aim
            agent.session.LastAim(agent.customId, activeTarget.transform.position, transform.position);
        }

        if (nextAIUpdate > Time.time)
        {
            nextAIUpdate = Time.time + Random.Range(0.5f, 1f);
        }

        SearchForTarget();
        GetSupport();
        GetAction();
        DoPath();

        if (activeTarget == null && agent.heroType == Callipso.HeroType.Creature && PhysikEngine.GetDistance(transform.position, SpawnPoint) > 1)
        {
            Vector3 export = Vector3.zero;
            GetPath(SpawnPoint); // Return the spawn point
        }
    }
示例#2
0
    public static bool isBlocked(ushort mapId, Vector3 cPosition, Vector3 tPosition, bool fixedMagnitude = true)
    {
        Vector3 direction = (tPosition - cPosition).normalized;

        int magnitude = (fixedMagnitude) ? 2 : Mathf.RoundToInt(PhysikEngine.GetDistance(cPosition, tPosition));

        if (magnitude < 1)
        {
            magnitude = 1;
        }
        for (int i = 1; i < magnitude; i++)
        {
            Vector3 position = cPosition + direction * i;
            if (position.x <= 0 || position.x > maps[mapId].mapSize || position.z <= 0 || position.z >= maps[mapId].mapSize)
            {
                return(true); // Out of bounds
            }
            bool c = maps[mapId].aStar.IsWalkableAt(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.z));

            if (!c)
            {
                return(true);
            }
        }

        return(false);
    }
示例#3
0
    void SearchForTarget()
    {
        if (activeTarget != null && activeTarget.agent.isDead)
        {
            activeTarget = null;
        }

        List <MobileAgent> agents = agent.session.agents.FindAll(x => x != agent &&
                                                                 (agent.session.teamsize == 0 || x.team != agent.team) &&
                                                                 !x.isDead &&
                                                                 PhysikEngine.GetDistance(x.transform.position, transform.position) < vision &&
                                                                 (agent.heroType == Callipso.HeroType.Player || (agent.heroType == Callipso.HeroType.Creature && x.heroType == Callipso.HeroType.Player)));

        if (agents.Count > 0)
        {
            if (activeTarget == null || activeTarget.agent.heroType == Callipso.HeroType.Creature)
            {
                activeTarget = agents[Random.Range(0, agents.Count)].physik;
            }
            return;
        }

        if (activeTarget == null && !agent.pointed && agent.heroType == Callipso.HeroType.Player)
        {
            List <MobileAgent> targetCreatures = agent.session.creatures.FindAll(x => x != null);
            if (targetCreatures.Count > 0)
            {
                activeTarget = targetCreatures[Random.Range(0, targetCreatures.Count)].physik;
                GetPath(activeTarget.transform.position);
                return;
            }
        }

        /*
         * NO TARGET FOUND, LET's PICK A RANDOM Target
         * */

        if (agent._hero.heroType == Callipso.HeroType.Player && (targetPath == null || targetPath.Count == 0))
        {
            agents = agent.session.agents.FindAll(x =>
                                                  (agent.session.teamsize == 0 || x.team != agent.team) &&
                                                  !x.isDead &&
                                                  (agent.heroType == Callipso.HeroType.Player || (agent.heroType == Callipso.HeroType.Creature && x.heroType == Callipso.HeroType.Player)));

            if (agents.Count > 0)
            {
                GetPath(agents[Random.Range(0, agents.Count)].transform.position);
            }
        }
    }
示例#4
0
    void Update()
    {
        if (tolerance > 0)
        {
            tolerance -= Time.deltaTime * 2;
        }

        if (nextSpamCounter < Time.time)
        {
            if (spammer > 0)
            {
                spammer--;              // Reduce the spammer
            }
            nextSpamCounter = Time.time + 0.03f;
        }

        if (nextSync < Time.time)
        {
            nextSync = Time.time + 0.5f;
            if (session.isStarted)
            {
                SyncPosition();
            }
        }

        CheckSkill();

        if (nextMove > Time.time || isDead || session.killed)
        {
            return;
        }

        if (pointed)
        {
            if (PhysikEngine.GetDistance(transform.position, targetPoint) < 0.1f)
            {
                targetPoint = Vector3.up;
            }
            else
            {
                if (skillStart < Time.time)
                {
                    transform.position += (targetPoint - transform.position).normalized * moveSpeed * Time.deltaTime; // if its casting, just rotate, don't move
                }
                transform.rotation = Quaternion.LookRotation(targetPoint - transform.position);
            }
        }
    }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        if (nextControl > Time.time)
        {
            return;
        }

        if (agent == null)
        {
            Destroy(gameObject);
        }

        nextControl = Time.time + updateTime;

        if (SearchForCollision)
        {
            if (MapLoader.isBlocked(session.map, transform.position, transform.position + transform.forward))
            {
                gameObject.SendMessage("Kill");
                return;
            }

            List <MobileAgent> _list = new List <MobileAgent>();
            PhysikEngine.FindCollision(session.id, transform.position, radius + (transform.position - lastPos).magnitude, out _list);

            lastPos = transform.position;
            if (!hitContinous)
            {
                int c = alreadyHit.Count;
                for (int i = 0; i < c; i++)
                {
                    _list.Remove(alreadyHit[i]);
                }

                alreadyHit.AddRange(_list);
            }

            if (_list.Count == 0)
            {
                return;
            }

            gameObject.SendMessage("PhysikHit", _list);
        }
    }
示例#6
0
    public static Vector3 latestPoint(ushort mapId, Vector3 position1, Vector3 position2)
    {
        position1.y = 0;
        position2.y = 0;

        Vector3 normal          = (position2 - position1).normalized;
        float   currentDistance = 100;

        while (currentDistance > 1)
        {
            currentDistance = PhysikEngine.GetDistance(position2, position1);
            position1      += normal;

            if (isPositionBlocked(mapId, position1))
            {
                return(position1 - normal);
            }
        }

        return(position2);
    }
示例#7
0
    void DoPath()
    {
        if (targetPath != null && targetPath.Count > 0)
        {
            if (PhysikEngine.GetDistance(transform.position, targetPath[targetNode]) < 0.5f)
            {
                targetNode++;

                if (targetNode >= targetPath.Count)
                {
                    targetPath = new List <Vector3>();
                    targetNode = 0;
                    return;
                }
            }

            if (agent.skillStart == 0f && targetPath.Count > 0)
            {
                agent.targetPoint = targetPath[targetNode];
            }
        }
    }
示例#8
0
    public void CheckSkill()
    {
        if (skillStart != 0 && (lastAimReceived || skillStart < Time.time - 1 || user == null) && skillStart < Time.time)
        {
            lastAimReceived = false;
            skillStart      = 0f;
            nextMove        = Time.time + 0.5f;

            /*
             * CREATE SKILL
             * */
            if (!isDead)
            {
                Vector3 tPos = transform.position;

                bool isTeleport = skills[skillId].effectType == EffectType.Teleport;

                if (skills[skillId].skillType == SkillType.Area || isTeleport)
                { // Area Spell
                    Vector3 v = aimPoint;
                    if (PhysikEngine.GetDistance(aimPoint, tPos) > 10)
                    {
                        v = transform.position + (aimPoint - tPos).normalized * 10;
                    }

                    tPos = v;
                }

                if (isTeleport)
                { // TELEPORT SKILL
                    transform.position = MapLoader.latestPoint(session.map, transform.position, MapLoader.latestPoint(session.map, transform.position, tPos));
                    MObjects.Teleport tp = new MObjects.Teleport();
                    tp.id  = (user == null) ? customId : user.connectionId;
                    tp.pos = transform.position;

                    int _ca = session.users.Count;
                    for (int i = 0; i < _ca; i++)
                    {
                        if (NetworkServer.connections.Contains(session.users[i]))
                        {
                            // send the mobject
                            NetworkServer.SendToClient(session.users[i].connectionId, MTypes.Teleport, tp);
                        }
                    }
                }
                else if (!MapLoader.isBlocked(session.map, transform.position, tPos, false))
                { // OTHERs
                    GameObject skill = new GameObject("skill");
                    Skill      s     = skill.AddComponent <Skill>();
                    session.createdSkills.Add(skill);
                    s.id                 = ((user != null) ? user.connectionId : customId) + "_" + castedSkill++;
                    s.clientPrefab       = skills[skillId].clientPrefab;
                    s.moveSpeed          = skills[skillId].moveSpeed;
                    s.skillType          = skills[skillId].skillType;
                    s.life               = skills[skillId].life;
                    s.effectTime         = skills[skillId].effectTime;
                    s.session            = session;
                    s.hitAndDestroy      = skills[skillId].hitAndDestroy;
                    s.collision          = skills[skillId].collision;
                    s.effect             = skills[skillId].GetEffect(this);
                    s.effectType         = skills[skillId].effectType;
                    s.hitContinous       = skills[skillId].hitContinous;
                    s.transform.rotation = transform.rotation;
                    s.activeAfter        = skills[skillId].activeAfter;
                    s.caster             = this;
                    s.transform.position = tPos;

                    if (skills[skillId].skillType == SkillType.Self)
                    {
                        // This is a self type skill. Hit & Destroy Immediately.

                        List <MobileAgent> self = new List <MobileAgent>();
                        self.Add(this);
                        s.PhysikHit(self);

                        Destroy(skill);
                    }
                }

                cooldowns[skillId] = Time.time + skills[skillId].cooldown - (skills[skillId].cooldown * agentLevel.level.Percent_cooldown / 100f);

                if (user != null && NetworkServer.connections.Contains(user))
                {
                    MObjects.Cooldown _mObject = new MObjects.Cooldown();
                    _mObject.skillId = skillId;
                    _mObject.time    = cooldowns[skillId] - Time.time;

                    NetworkServer.SendToClient(user.connectionId, MTypes.Cooldown, _mObject);
                }
            }

            /*
             * */

            Stop();

            MObjects.EndSkill mObject = new MObjects.EndSkill();
            mObject.id = (user != null) ? user.connectionId: customId;

            int _c = session.users.Count;
            for (int i = 0; i < _c; i++)
            {
                if (NetworkServer.connections.Contains(session.users[i]))
                {
                    // send the mobject
                    NetworkServer.SendToClient(session.users[i].connectionId, MTypes.EndSkill, mObject);
                }
            }
        }
    }
示例#9
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;
            }
        }
        //
    }
示例#10
0
    void GetAction()
    {
        if (skills_attack.Length == 0)
        {
            return;
        }

        if (agent.skillStart != 0f)
        {
            return; // already in action
        }
        if (activeTarget != null)
        {
            distanceToActive = PhysikEngine.GetDistance(activeTarget.transform.position, transform.position);

            if (distanceToActive > vision)
            {
                activeTarget = null;
                return;
            }

            else if (!MapLoader.isBlocked(agent.session.map, transform.position, activeTarget.transform.position, false))  // TARGET IN SIGHT, SEARCH FOR SKILLS OR NOT MOVE TO TARGET
            {
                short tSpell = -1;

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

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

                ushort rVal = (ushort)clist.Length;

                for (ushort r = 0; r < rVal; r++)
                {
                    ushort idx = (ushort)agent.skills.ToList().FindIndex(x => x == skills_attack[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;
                }

                if (agent.skills[rVal].skillType != SkillType.Self)
                {
                    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;
                    }
                }
                else
                {
                    tSpell = (short)rVal;
                }

                if (tSpell != -1)
                {
                    /*
                     * CAST SPELL
                     * */
                    agent.session.LastAim(agent.customId, activeTarget.transform.position, transform.position);
                    agent.session.SkillRequest(agent.customId, (ushort)tSpell);
                    return;
                }
            }

            GetPath(activeTarget.transform.position);
        }
    }
示例#11
0
    private void Update()
    {
        // Buff controller
        if (nextUpdate > Time.time)
        {
            return;
        }

        nextUpdate = Time.time + 1;

        int bCount = buff.buffs.Count;

        List <Buffing.Buff> willRemove = new List <Buffing.Buff>();

        for (int i = 0; i < bCount; i++)
        {
            Buffing.Buff b = buff.buffs[i];

            if (b.buffTime == 1)
            {
                willRemove.Add(b);
            }
            else if (b.buffTime != 0) // 0 means permanent buff
            {
                b.buffTime--;
            }

            if (myAgent.isDead)
            {
                continue;
            }

            List <MobileAgent> targetAgents = new List <MobileAgent>();
            int fCount = 0;
            switch (b.buffType)
            {
            case Buffing.buffTypes.DamagerObject:     // Damager object
                targetAgents = myAgent.session.agents.FindAll(x => (x != myAgent && (x.team != myAgent.team || myAgent.session.teamsize == 0)) && !x.isDead && PhysikEngine.GetDistance(x.transform.position, myAgent.transform.position) <= 4);

                fCount = targetAgents.Count;
                for (int f = 0; f < fCount; f++)
                {
                    targetAgents[f].lastHitter = (myAgent.user == null) ? myAgent.customId : myAgent.user.connectionId;
                    targetAgents[f].health    -= b.GetBuffEffect(myAgent);
                }
                break;

            case Buffing.buffTypes.Healer:     // Healer objects
                targetAgents = myAgent.session.agents.FindAll(x => (x == myAgent || (x.team == myAgent.team && myAgent.session.teamsize != 0)) && !x.isDead && (x == myAgent || PhysikEngine.GetDistance(x.transform.position, myAgent.transform.position) <= 8));

                fCount = targetAgents.Count;
                for (int f = 0; f < fCount; f++)
                {
                    targetAgents[f].health += b.GetBuffEffect(myAgent);
                }
                break;

            case Buffing.buffTypes.Poison:      // Self poison
                myAgent.health -= b.buffEffect;
                break;
            }
        }

        int wCount = willRemove.Count;

        for (int i = 0; i < wCount; i++)
        {
            buff.buffs.Remove(willRemove[i]);
        }

        if (wCount > 0)
        {
            myAgent.AgentInfo();
        }

        /*
         * UPDATE BUFF
         * */

        mObject.buffs = buff.buffs.ToArray();

        wCount           = mObject.buffs.Length;
        mObject.modified = new short[wCount];

        for (int i = 0; i < wCount; i++)
        {
            mObject.modified [i] = mObject.buffs[i].GetBuffEffect(myAgent);
        }

        /*
         * THIS WILL SEND mObject to ALL CLIENTS
         * */

        wCount = myAgent.session.users.Count;
        for (ushort i = 0; i < wCount; i++)
        {
            if (NetworkServer.connections.Contains(myAgent.session.users[i]))
            {
                NetworkServer.SendToClient(myAgent.session.users[i].connectionId, MTypes.AgentBuff, mObject);
            }
        }
    }