Exemple #1
0
        public void Update(ComponentPlayer localPlayer)
        {
            VisibleEntities.Clear();
            LivingEnitites.Clear();
            //refresh context
            if (localPlayer != null)
            {
                LocalPlayer = localPlayer.Owner;
                float closestDist  = Mathf.Infinity;
                float closestvDist = closestDist;
                foreach (AgentHumanDT agentHumanDT in Mission.Instance.CurrentGameZone.Agents)
                {
                    if (agentHumanDT.IsAlive && !agentHumanDT.IsFriend(LocalPlayer))
                    {
                        LivingEnitites.Add(agentHumanDT);
                        HitUtils.HitData data;
                        bool             targetFound;
                        WeaponBase       weapon   = LocalPlayer.WeaponComponent.GetCurrentWeapon();
                        Vector3          startPos = LocalPlayer.Position;
                        startPos.y += 1.7f;
                        weapon.ComputeAimAssistDir(startPos, agentHumanDT.EyePosition - startPos, out targetFound, out data);
                        if (targetFound)
                        {
                            float vdist = Vector3.Distance(agentHumanDT.transform.position, localPlayer.transform.position);
                            if (closestvDist > vdist)
                            {
                                closestvDist   = vdist;
                                ClosestVEntity = agentHumanDT;
                            }
                            VisibleEntities.Add(agentHumanDT);
                        }

                        /*RaycastHit hit;
                         * if (Physics.SphereCast(localPlayer.Owner.EyePosition, 5f, agentHumanDT.ChestPosition - localPlayer.Owner.EyePosition, out hit, 100f, -5, QueryTriggerInteraction.UseGlobal))
                         * {
                         *  AgentHumanDT target;
                         *  int offset = 0;
                         *  do
                         *  {
                         *      target = m_SearchDelegates[offset](hit.transform);
                         *      offset++;
                         *  }
                         *  while (target == null && offset < m_SearchDelegates.Length);
                         *  if (target != null)
                         *      VisibleEntities.Add(agentHumanDT);
                         * }*/
                        float dist = Vector3.Distance(agentHumanDT.transform.position, localPlayer.transform.position);
                        if (closestDist > dist)
                        {
                            closestDist   = dist;
                            ClosestEntity = agentHumanDT;
                        }
                    }
                }
            }
            Utils.NativeLMSLog(string.Format("Context update: v {0} l {1} p {2}", VisibleEntities.Count, LivingEnitites.Count, localPlayer != null));
        }
Exemple #2
0
        protected override Vector2 DangerAcceleration()
        {
            var predators = VisibleEntities.OfType <Predator>().Where(b => b.IsAlive).ToList();

            var acceleration = new Vector2(0, 0);

            acceleration += Vector2.Multiply(Flee(predators), 7f);

            return(acceleration);
        }
Exemple #3
0
        protected Vector2 Separate(float desiredSeperation)
        {
            var steer = new Vector2(0, 0);

            var others = VisibleEntities.OfType <Being>().Where(being => being.IsAlive && being.GetType() == GetType());

            if (!others.Any())
            {
                return(steer);
            }

            foreach (var other in others)
            {
                if (other == this)
                {
                    continue;
                }

                var distance = VectorHelper.TorusDistance(Position, other.Position);

                if (distance < desiredSeperation)
                {
                    var difference = Vector2.Subtract(Position, other.Position);
                    if (difference.Length() > 0)
                    {
                        difference = Vector2.Normalize(difference);
                    }

                    // Weight by distance
                    if (distance != 0)
                    {
                        difference = Vector2.Divide(difference, distance);
                    }

                    steer = Vector2.Add(steer, difference);
                }
            }

            steer = Vector2.Divide(steer, others.Count());

            if (steer.Length() > 0)
            {
                if (steer.Length() > 0)
                {
                    steer = Vector2.Normalize(steer);
                }
                steer = Vector2.Multiply(steer, MaxSpeed);
                steer = Vector2.Subtract(steer, Velocity);

                steer = VectorHelper.Limit(steer, MaxForce);
            }

            return(steer);
        }
Exemple #4
0
        protected override Vector2 HungryAcceleration()
        {
            var boids     = VisibleEntities.OfType <Boid>().Where(b => b.IsAlive).ToList();
            var predators = VisibleEntities.OfType <Predator>().Where(b => b.IsAlive).ToList();

            var acceleration = new Vector2(0, 0);

            acceleration += Vector2.Multiply(Flee(predators), 2f);
            acceleration += Vector2.Multiply(Separate(10f), 0.5f);
            acceleration += Vector2.Multiply(Align(boids), 0.5f);
            acceleration += Vector2.Multiply(Cohesion(boids), 0.5f);

            acceleration += Vector2.Multiply(Hunt(), 5f);
            acceleration += Vector2.Multiply(Attack(), 10f);

            return(acceleration);
        }
Exemple #5
0
        private void HandleDC(byte[] message)
        {
            Logger.Log(username + " Disconnected.");
            GlobalMessage(username + " Left.");

            /*if (OnDisconnect != null)
             *  OnDisconnect(this);
             * if (PlayerDisconnect != null)
             *  PlayerDisconnect(this);*/
            PlayerDisconnectEvent.Call(this);
            socket.Close();
            Disconnect();
            foreach (int i in VisibleEntities.ToArray())
            {
                try
                {
                    Entity e = Entity.Entities[i];
                    e.p.SendDespawn(id);
                }
                catch { /* Ignore Me */ }
            }
        }
Exemple #6
0
        private void SetDirection()
        {
            if (ThinkCooldown > 1)
            {
                ThinkCooldown--;
                return;
            }

            var entities = VisibleEntities.ToList();

            //if (CheckFlee(entities)) return;

            ChooseForceDirections(entities);

            if (Random.Next(100) != 0)
            {
                return;
            }

            ChangeColor(WanderingColor);
            ChooseRandomDirection();
            ThinkCooldown = RndThinkDelay(200, 2, 100);
        }
        private void HandleWindowClick(byte[] message)
        {
            short     slot     = util.EndianBitConverter.Big.ToInt16(message, 1);
            ClickType click    = (ClickType)message[3];
            short     ActionID = util.EndianBitConverter.Big.ToInt16(message, 4);
            bool      Shift    = (message[6] == 1);

            //Console.WriteLine(String.Format("{0} {1} {2}", click, slot, Shift));
            if (HasWindowOpen)
            {
                window.HandleClick(this, slot, click, ActionID, Shift);
            }
            else
            {
                inventory.HandleClick(slot, click, ActionID, Shift);
            }

            if (!HasWindowOpen)
            {
                if (slot == 5)
                {
                    foreach (int i in VisibleEntities.ToArray())
                    {
                        Entity e = Entity.Entities[i];
                        if (!e.isPlayer)
                        {
                            continue;
                        }
                        e.p.SendEntityEquipment(id, 4, inventory.items[5].id, 0);
                    }
                }
                else if (slot == 6)
                {
                    foreach (int i in VisibleEntities.ToArray())
                    {
                        Entity e = Entity.Entities[i];
                        if (!e.isPlayer)
                        {
                            continue;
                        }
                        e.p.SendEntityEquipment(id, 3, inventory.items[6].id, 0);
                    }
                }
                else if (slot == 7)
                {
                    foreach (int i in VisibleEntities.ToArray())
                    {
                        Entity e = Entity.Entities[i];
                        if (!e.isPlayer)
                        {
                            continue;
                        }
                        e.p.SendEntityEquipment(id, 2, inventory.items[7].id, 0);
                    }
                }
                else if (slot == 8)
                {
                    foreach (int i in VisibleEntities.ToArray())
                    {
                        Entity e = Entity.Entities[i];
                        if (!e.isPlayer)
                        {
                            continue;
                        }
                        e.p.SendEntityEquipment(id, 1, inventory.items[8].id, 0);
                    }
                }
                else if (slot == inventory.current_index)
                {
                    foreach (int i in VisibleEntities.ToArray())
                    {
                        Entity e = Entity.Entities[i];
                        if (!e.isPlayer)
                        {
                            continue;
                        }
                        e.p.SendEntityEquipment(id, 0, inventory.current_item.id, 0);
                    }
                }
            }
            else
            {
                byte currentc = (byte)((current_slot_holding - 9) + window.InventorySize); //TODO TEST
                if (slot == currentc)
                {
                    foreach (int i in VisibleEntities.ToArray())
                    {
                        Entity e = Entity.Entities[i];
                        if (!e.isPlayer)
                        {
                            continue;
                        }
                        e.p.SendEntityEquipment(id, 0, inventory.current_item.id, 0);
                    }
                }
            }

            if (HasWindowOpen)
            {
                if (slot < 5)
                {
                    // GlobalMessage(GetName() + " " + window.items[1].item);
                }
            }
            else
            {
                if (slot < 10)
                {
                    // GlobalMessage(GetName() + inventory.items[1].item);
                }
            }
        }