Example #1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ItemId != 0)
            {
                hash ^= ItemId.GetHashCode();
            }
            if (ItemType != 0)
            {
                hash ^= ItemType.GetHashCode();
            }
            if (ItemDesc.Length != 0)
            {
                hash ^= ItemDesc.GetHashCode();
            }
            if (ItemVoice.Length != 0)
            {
                hash ^= ItemVoice.GetHashCode();
            }
            if (ItemPhiz.Length != 0)
            {
                hash ^= ItemPhiz.GetHashCode();
            }
            if (Player != 0)
            {
                hash ^= Player.GetHashCode();
            }
            return(hash);
        }
Example #2
0
        //---------------------------------------------------------------------------

        public int TryAdd(EItemType type, int count)
        {
            ItemDesc item = ItemManager.Get().Find(type);

            if (!item.IsEmpty)
            {
                int remaining = count;
                int index     = 0;
                do
                {
                    index = GetFirstNonFullSlot(type);
                    if (index >= 0)
                    {
                        if (m_Items[index] == null)
                        {
                            m_Items[index] = new InventorySlot(item);
                            if (index == ActiveIndex)
                            {
                                if (index == ActiveIndex)
                                {
                                    UpdateWeapon();
                                }
                            }
                        }
                        remaining = m_Items[index].Add(remaining);
                    }
                }while (remaining > 0 && index >= 0);
                return(remaining);
            }
            return(count);
        }
Example #3
0
        /// <summary>
        /// Gets all the items that our business sells.
        /// </summary>
        /// <returns></returns>
        public List <ItemDesc> getItems()
        {
            try
            {
                List <ItemDesc> items = new List <ItemDesc>();

                DataSet ds;
                int     numberOfRowsReturned = 0;
                ds = dbManager.ExecuteSQLStatement(sqlStatements.GetItems(), ref numberOfRowsReturned);
                ItemDesc item;
                for (int i = 0; i < numberOfRowsReturned; i++)
                {
                    item                 = new ItemDesc();
                    item.itemCode        = ds.Tables[0].Rows[i][0].ToString();
                    item.itemDescription = ds.Tables[0].Rows[i][1].ToString();
                    string itemCost = ds.Tables[0].Rows[i][2].ToString();
                    item.cost = convertStringToDecimal(itemCost);

                    items.Add(item);
                }

                return(items);
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
Example #4
0
 private void ClearPopup()
 {
     mItemToBuy     = null;
     mDiamondsToBuy = null;
     MessageBox.gameObject.SetActive(false);
     DialogBox.gameObject.SetActive(false);
 }
Example #5
0
    public void ShowSlot(ItemDesc item = null)
    {
        foreach (GameObject obj in SlotsRenderer)
        {
            cObject o = obj.GetComponent <cObject>();
            if (item != null && item.Type == TypeItem.Meuble && item.Slots.Contains(o.pType))
            {
                obj.renderer.enabled = true;
            }
            else
            {
                obj.renderer.enabled = false;
            }

            if (item != null)
            {
                foreach (GameObject carton in o.Cartons)
                {
                    carton.renderer.enabled = !obj.renderer.enabled && !HasItemAt(o);
                }
            }
            else
            {
                foreach (GameObject carton in o.Cartons)
                {
                    carton.renderer.enabled = !HasItemAt(o);
                }
            }
        }
    }
Example #6
0
        //---------------------------------------------------------------------------

        public void RegisterItem(ItemDesc item)
        {
            if (!m_Items.ContainsKey(item.Type))
            {
                m_Items.Add(item.Type, item);
            }
        }
        public int GetNextDamageSeeded(int min, int max, int data)
        {
            float dmgMod = ItemDesc.GetStat(data, ItemData.Damage, ItemDesc.DamageMultiplier);
            int   minDmg = min + (int)(min * dmgMod);
            int   maxDmg = max + (int)(max * dmgMod);

            return((int)Client.Random.NextIntRange((uint)minDmg, (uint)maxDmg));
        }
        public int GetNextDamage(int min, int max, int data)
        {
            float dmgMod = ItemDesc.GetStat(data, ItemData.Damage, ItemDesc.DamageMultiplier);
            int   minDmg = min + (int)(min * dmgMod);
            int   maxDmg = max + (int)(max * dmgMod);

            return(MathUtils.NextInt(minDmg, maxDmg));
        }
Example #9
0
        //---------------------------------------------------------------------------

        public Color GetColorByType(EItemType type)
        {
            ItemDesc desc = Find(type);

            if (!desc.IsEmpty)
            {
                return(GetColorByRarity(desc.Rarity));
            }
            return(Color.White);
        }
Example #10
0
 public void UpdateCountItem(ItemDesc item)
 {
     foreach (GameDataItem it in Data.Inventory)
     {
         if (it.ItemDetail == item)
         {
             it.Number++;
             return;
         }
     }
 }
Example #11
0
 public void BuyItem(string name, TypePanel type)
 {
     if (type == TypePanel.Shop)
     {
         mItemToBuy = ItemsShop.GetItem(name);
     }
     else if (type == TypePanel.Diamonds)
     {
         mDiamondsToBuy = ItemsShop.GetDiamonds(name);
     }
     DialogBox.SetTextAndShow(CONFIRMATION_MSG + name);
 }
Example #12
0
    public void UseItem(string name)
    {
        string prefabName = name.Replace(" ", "_").Replace("é", "e");

        mItemGrab = GameObject.Instantiate(Resources.Load("Prefabs/Item/" + prefabName)) as GameObject;
        ItemDesc itemDesc = ItemsShop.GetItem(name);

        mItemGrab.GetComponent <Item>().ItemDesc = itemDesc;
        mDropItem = false;
        PanelGlobal.SetActive(false);
        ShowSlot(itemDesc);
    }
Example #13
0
        //---------------------------------------------------------------------------

        public void LoadItems()
        {
            Texture2D            itemSpritesheet = AssetManager.Get().Find <Texture2D>(ETilesetAssets.Items);
            List <ItemStoreDesc> items           = JsonConvert.DeserializeObject <List <ItemStoreDesc> >(Properties.Resources.Items);

            if (items != null)
            {
                foreach (ItemStoreDesc item in items)
                {
                    m_Items.Add(item.Type, ItemDesc.FromItemStoreDesc(itemSpritesheet, 14, 30, item));
                }
            }
        }
Example #14
0
 public void DecreaseCountItem(ItemDesc item)
 {
     foreach (GameDataItem it in Data.Inventory)
     {
         if (it.ItemDetail.Name == item.Name)
         {
             it.Number--;
             if (it.Number == 0)
             {
                 Data.Inventory.Remove(it);
             }
             return;
         }
     }
 }
Example #15
0
 /// <summary>
 /// Updates the selected item and the values in the text box.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ListBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         ItemDesc desc = (ItemDesc)((ListBox)sender).SelectedItem;
         if (desc != null)
         {
             txtCode.Text        = desc.itemCode;
             txtCost.Text        = "" + desc.cost;
             txtDescription.Text = desc.itemDescription;
         }
     }
     catch (System.Exception ex)
     {
         HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message);
     }
 }
Example #16
0
    public void ValidatedBuy()
    {
        bool ret = false;

        if (mItemToBuy != null)
        {
            ret = BuyItem();
        }
        else if (mDiamondsToBuy != null)
        {
            ret = BuyDiamonds();
        }
        if (!ret)
        {
            MessageBox.SetTextAndShow(ERROR_MSG);
        }
        mItemToBuy     = null;
        mDiamondsToBuy = null;
    }
Example #17
0
    int SortItems(ItemDesc x, ItemDesc y)
    {
        if (x.Owned != y.Owned && x.Owned == true)
        {
            return(-1);
        }
        if (x.Owned != y.Owned && x.Owned == false)
        {
            return(1);
        }

        if (x.Used > y.Used)
        {
            return(-1);
        }
        if (x.Used < y.Used)
        {
            return(1);
        }

        if (x.Rank > y.Rank)
        {
            return(-1);
        }
        if (x.Rank < y.Rank)
        {
            return(1);
        }

        if (x.Price > y.Price)
        {
            return(1);
        }
        if (x.Price < y.Price)
        {
            return(-1);
        }

        return(0);
    }
Example #18
0
 /// <summary>
 /// Returns all items in the items table
 /// </summary>
 /// <returns></returns>
 public List <ItemDesc> GetAllItems()
 {
     try
     {
         int             x         = 0;
         List <ItemDesc> itemsList = new List <ItemDesc>();
         DataSet         newData   = data.ExecuteSQLStatement(clsItemsSQL.ItemsSelectDescSQL(), ref x);
         for (int i = 0; i < x; i++)
         {
             ItemDesc desc = new ItemDesc();
             desc.itemCode        = (string)newData.Tables[0].Rows[i][0];
             desc.itemDescription = (string)newData.Tables[0].Rows[i][1];
             desc.cost            = (decimal)newData.Tables[0].Rows[i][2];
             itemsList.Add(desc);
         }
         return(itemsList);
     }
     catch (System.Exception ex)
     {
         throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
     }
 }
Example #19
0
        public void RecalculateEquipBonuses()
        {
            for (int i = 0; i < 8; i++)
            {
                Boosts[i] = 0;
            }

            for (int i = 0; i < 4; i++)
            {
                if (Inventory[i] == -1)
                {
                    continue;
                }

                ItemDesc item = Resources.Type2Item[(ushort)Inventory[i]];
                foreach (KeyValuePair <int, int> s in item.StatBoosts)
                {
                    Boosts[s.Key] += s.Value;
                }

                int data = ItemDatas[i];
                if (data == -1)
                {
                    continue;
                }

                Boosts[0] += (int)(ItemDesc.GetStat(data, ItemData.MaxHP, 5));
                Boosts[1] += (int)(ItemDesc.GetStat(data, ItemData.MaxMP, 5));
                Boosts[2] += (int)(ItemDesc.GetStat(data, ItemData.Attack, 1));
                Boosts[3] += (int)(ItemDesc.GetStat(data, ItemData.Defense, 1));
                Boosts[4] += (int)(ItemDesc.GetStat(data, ItemData.Speed, 1));
                Boosts[5] += (int)(ItemDesc.GetStat(data, ItemData.Dexterity, 1));
                Boosts[6] += (int)(ItemDesc.GetStat(data, ItemData.Vitality, 1));
                Boosts[7] += (int)(ItemDesc.GetStat(data, ItemData.Wisdom, 1));
            }

            UpdateStats();
        }
Example #20
0
    private bool CheckItemToCollider(GameObject obj)
    {
        ItemDesc itemDesc = mItemGrab.GetComponent <Item>().ItemDesc;

        switch (itemDesc.Type)
        {
        case TypeItem.Consommable:
            if (obj.CompareTag("Player"))
            {
                return(true);
            }
            break;

        case TypeItem.Assurance:
            if (obj.CompareTag("Player"))
            {
                return(true);
            }
            break;

        case TypeItem.Meuble:
            cObject cObj = obj.GetComponent <cObject>();
            if (!cObj)
            {
                break;
            }
            if (itemDesc.Slots.Contains(cObj.pType))
            {
                return(true);
            }
            break;

        default:
            break;
        }
        return(false);
    }
Example #21
0
        //---------------------------------------------------------------------------

        public void TryUpdate(ItemDesc desc)
        {
            Sprite.Sprite = desc.Sprite;
        }
Example #22
0
        //---------------------------------------------------------------------------

        public InventorySlot(ItemDesc item)
        {
            Item = item;
        }
Example #23
0
        public void TryUseItem(int time, SlotData slot, Position target)
        {
            if (!ValidTime(time))
            {
#if DEBUG
                Program.Print(PrintType.Error, "Invalid time useitem");
#endif
                Client.Disconnect();
                return;
            }

            if (slot.SlotId == HealthPotionSlotId)
            {
                if (HealthPotions > 0 && !HasConditionEffect(ConditionEffectIndex.Sick))
                {
                    Heal(100, false);
                    HealthPotions--;
                }
                return;
            }
            else if (slot.SlotId == MagicPotionSlotId)
            {
                if (MagicPotions > 0 && !HasConditionEffect(ConditionEffectIndex.Quiet))
                {
                    Heal(100, true);
                    MagicPotions--;
                }
                return;
            }

            Entity en = Parent.GetEntity(slot.ObjectId);
            if (slot.SlotId != 1)
            {
                (en as IContainer)?.UpdateInventorySlot(slot.SlotId);
            }
            if (en == null || !(en is IContainer))
            {
#if DEBUG
                Program.Print(PrintType.Error, "Undefined entity");
#endif
                return;
            }

            if (en is Player && !en.Equals(this))
            {
#if DEBUG
                Program.Print(PrintType.Error, "Trying to use items from another players inventory");
#endif
                return;
            }

            if (en is Container c)
            {
                if ((en as Container).OwnerId != -1 && (en as Container).OwnerId != Id)
                {
#if DEBUG
                    Program.Print(PrintType.Error, "Trying to use items from another players container/bag");
#endif
                    return;
                }

                if (en.Position.Distance(this) > ContainerMinimumDistance)
                {
#if DEBUG
                    Program.Print(PrintType.Error, "Too far away from container");
#endif
                    return;
                }
            }

            IContainer con  = en as IContainer;
            ItemDesc   desc = null;
            if (con.Inventory[slot.SlotId] != -1)
            {
                desc = Resources.Type2Item[(ushort)con.Inventory[slot.SlotId]];
            }

            if (desc == null)
            {
#if DEBUG
                Program.Print(PrintType.Error, "Invalid use item");
#endif
                return;
            }

            bool isAbility = slot.SlotId == 1;
            if (isAbility)
            {
                if (slot.ObjectId != Id)
                {
#if DEBUG
                    Program.Print(PrintType.Error, "Trying to use ability from a container?");
#endif
                    return;
                }

                if (UseTime + (UseDuration * (1f / UseCooldownThreshold)) > time)
                {
#if DEBUG
                    Program.Print(PrintType.Error, "Used ability too soon");
#endif
                    return;
                }

                if (MP - desc.MpCost < 0)
                {
#if DEBUG
                    Program.Print(PrintType.Error, "Not enough MP");
#endif
                    return;
                }
            }

            bool   inRange  = Position.Distance(target) <= MaxAbilityDist && Parent.GetTileF(target.X, target.Y) != null;
            Action callback = null;
            foreach (ActivateEffectDesc eff in desc.ActivateEffects)
            {
                switch (eff.Index)
                {
                case ActivateEffectIndex.Shuriken:     //Could be optimized too, it's not great..
                {
                    byte[] nova = GameServer.ShowEffect(ShowEffectIndex.Nova, Id, 0xffeba134, new Position(2.5f, 0));

                    foreach (Entity j in Parent.EntityChunks.HitTest(Position, 2.5f))
                    {
                        if (j is Enemy k &&
                            !k.HasConditionEffect(ConditionEffectIndex.Invincible) &&
                            !k.HasConditionEffect(ConditionEffectIndex.Stasis))
                        {
                            k.ApplyConditionEffect(ConditionEffectIndex.Dazed, 1000);
                        }
                    }

                    List <byte[]>    stars  = new List <byte[]>();
                    HashSet <Entity> seeked = new HashSet <Entity>();
                    int startId             = NextAEProjectileId;
                    NextAEProjectileId += eff.Amount;

                    float angle = Position.Angle(target);
                    float cone  = MathF.PI / 8;
                    for (int i = 0; i < eff.Amount; i++)
                    {
                        Entity t = this.GetNearestEnemy(8, angle, cone, target, seeked) ?? this.GetNearestEnemy(6, seeked);
                        if (t != null)
                        {
                            seeked.Add(t);
                        }
                        int   d = GetNextDamage(desc.Projectile.MinDamage, desc.Projectile.MaxDamage, ItemDatas[slot.SlotId]);
                        float a = t == null?MathUtils.NextAngle() : Position.Angle(t.Position);

                        List <Projectile> p = new List <Projectile>()
                        {
                            new Projectile(this, desc.Projectile, startId + i, time, a, Position, d)
                        };

                        stars.Add(GameServer.ServerPlayerShoot(startId + i, Id, desc.Type, Position, a, 0, p));
                        AwaitProjectiles(p);
                    }

                    foreach (Entity j in Parent.PlayerChunks.HitTest(Position, SightRadius))
                    {
                        if (j is Player k)
                        {
                            if (k.Client.Account.Effects || k.Equals(this))
                            {
                                k.Client.Send(nova);
                            }
                            if (k.Client.Account.AllyShots || k.Equals(this))
                            {
                                foreach (byte[] s in stars)
                                {
                                    k.Client.Send(s);
                                }
                            }
                        }
                    }
                }
                break;

                case ActivateEffectIndex.VampireBlast:     //Maybe optimize this...?
                    if (inRange)
                    {
                        byte[] line       = GameServer.ShowEffect(ShowEffectIndex.Line, Id, 0xFFFF0000, target);
                        byte[] burst      = GameServer.ShowEffect(ShowEffectIndex.Burst, Id, 0xFFFF0000, target, new Position(target.X + eff.Radius, target.Y));
                        int    lifeSucked = 0;

                        List <Entity> enemies = new List <Entity>();
                        List <Entity> players = new List <Entity>();
                        List <byte[]> flows   = new List <byte[]>();

                        foreach (Entity j in Parent.EntityChunks.HitTest(target, eff.Radius))
                        {
                            if (j is Enemy k &&
                                !k.HasConditionEffect(ConditionEffectIndex.Invincible) &&
                                !k.HasConditionEffect(ConditionEffectIndex.Stasis))
                            {
                                k.Damage(this, eff.TotalDamage, eff.Effects, true, true);
                                lifeSucked += eff.TotalDamage;
                                enemies.Add(k);
                            }
                        }

                        foreach (Entity j in Parent.PlayerChunks.HitTest(Position, eff.Radius))
                        {
                            if (j is Player k)
                            {
                                players.Add(k);
                                k.Heal(lifeSucked, false);
                            }
                        }

                        if (enemies.Count > 0)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                Entity a = enemies[MathUtils.Next(enemies.Count)];
                                Entity b = players[MathUtils.Next(players.Count)];
                                flows.Add(GameServer.ShowEffect(ShowEffectIndex.Flow, b.Id, 0xffffffff, a.Position));
                            }
                        }

                        foreach (Entity j in Parent.PlayerChunks.HitTest(Position, SightRadius))
                        {
                            if (j is Player k)
                            {
                                if (k.Client.Account.Effects)
                                {
                                    k.Client.Send(line);
                                    foreach (byte[] p in flows)
                                    {
                                        k.Client.Send(p);
                                    }
                                }

                                if (k.Client.Account.Effects || k.Equals(this))
                                {
                                    k.Client.Send(burst);
                                }
                            }
                        }
                    }
                    break;

                case ActivateEffectIndex.StasisBlast:
                    if (inRange)
                    {
                        byte[] blast = GameServer.ShowEffect(ShowEffectIndex.Collapse, Id, 0xffffffff,
                                                             target,
                                                             new Position(target.X + 3, target.Y));
                        List <byte[]> notifications = new List <byte[]>();

                        foreach (Entity j in Parent.EntityChunks.HitTest(target, 3))
                        {
                            if (j is Enemy k)
                            {
                                if (k.HasConditionEffect(ConditionEffectIndex.StasisImmune))
                                {
                                    notifications.Add(GameServer.Notification(k.Id, "Immune", 0xff00ff00));
                                    continue;
                                }

                                if (k.HasConditionEffect(ConditionEffectIndex.Stasis))
                                {
                                    continue;
                                }

                                notifications.Add(GameServer.Notification(k.Id, "Stasis", 0xffff0000));
                                k.ApplyConditionEffect(ConditionEffectIndex.Stasis, eff.DurationMS);
                                k.ApplyConditionEffect(ConditionEffectIndex.StasisImmune, eff.DurationMS + 3000);
                            }
                        }

                        foreach (Entity j in Parent.PlayerChunks.HitTest(Position, SightRadius))
                        {
                            if (j is Player k)
                            {
                                if (k.Client.Account.Effects || k.Equals(this))
                                {
                                    k.Client.Send(blast);
                                }
                                if (k.Client.Account.Notifications || k.Equals(this))
                                {
                                    foreach (byte[] n in notifications)
                                    {
                                        k.Client.Send(n);
                                    }
                                }
                            }
                        }
                    }
                    break;

                case ActivateEffectIndex.Trap:
                    if (inRange)
                    {
                        byte[] @throw = GameServer.ShowEffect(ShowEffectIndex.Throw, Id, 0xff9000ff, target);
                        foreach (Entity j in Parent.PlayerChunks.HitTest(Position, SightRadius))
                        {
                            if (j is Player k && (k.Client.Account.Effects || k.Equals(this)))
                            {
                                k.Client.Send(@throw);
                            }
                        }

                        Manager.AddTimedAction(1500, () =>
                        {
                            if (Parent != null)
                            {
                                Parent.AddEntity(new Trap(this, eff.Radius, eff.TotalDamage, eff.Effects), target);
                            }
                        });
                    }
                    break;

                case ActivateEffectIndex.Lightning:
                {
                    float  angle = Position.Angle(target);
                    float  cone  = MathF.PI / 4;
                    Entity start = this.GetNearestEnemy(MaxAbilityDist, angle, cone, target);

                    if (start == null)
                    {
                        float[] angles = new float[3] {
                            angle, angle - cone, angle + cone
                        };
                        byte[][] lines = new byte[3][];
                        for (int i = 0; i < 3; i++)
                        {
                            float x = (int)(MaxAbilityDist * MathF.Cos(angles[i])) + Position.X;
                            float y = (int)(MaxAbilityDist * MathF.Sin(angles[i])) + Position.Y;
                            lines[i] = GameServer.ShowEffect(ShowEffectIndex.Line, Id, 0xffff0088, new Position(x, y), new Position(350, 0));
                        }

                        foreach (Entity j in Parent.PlayerChunks.HitTest(Position, SightRadius))
                        {
                            if (j is Player k && k.Client.Account.Effects)
                            {
                                k.Client.Send(lines[0]);
                                k.Client.Send(lines[1]);
                                k.Client.Send(lines[2]);
                            }
                        }
                    }
                    else
                    {
                        Entity           prev    = this;
                        Entity           current = start;
                        HashSet <Entity> targets = new HashSet <Entity>();
                        List <byte[]>    pkts    = new List <byte[]>();
                        targets.Add(current);
                        (current as Enemy).Damage(this, eff.TotalDamage, eff.Effects, false, true);
                        for (int i = 1; i < eff.MaxTargets + 1; i++)
                        {
                            pkts.Add(GameServer.ShowEffect(ShowEffectIndex.Lightning, prev.Id, 0xffff0088,
                                                           new Position(current.Position.X, current.Position.Y),
                                                           new Position(350, 0)));

                            if (i == eff.MaxTargets)
                            {
                                break;
                            }

                            Entity next = current.GetNearestEnemy(10, targets);
                            if (next == null)
                            {
                                break;
                            }

                            targets.Add(next);
                            (next as Enemy).Damage(this, eff.TotalDamage, eff.Effects, false, true);
                            prev    = current;
                            current = next;
                        }

                        foreach (Entity j in Parent.PlayerChunks.HitTest(Position, SightRadius))
                        {
                            if (j is Player k && k.Client.Account.Effects)
                            {
                                foreach (byte[] p in pkts)
                                {
                                    Console.WriteLine(p.Length);
                                    k.Client.Send(p);
                                }
                            }
                        }
                    }
                }
                break;

                case ActivateEffectIndex.PoisonGrenade:
                    if (inRange)
                    {
                        Placeholder placeholder = new Placeholder();
                        Parent.AddEntity(placeholder, target);

                        byte[] @throw = GameServer.ShowEffect(ShowEffectIndex.Throw, Id, 0xffddff00, target);
                        byte[] nova   = GameServer.ShowEffect(ShowEffectIndex.Nova, placeholder.Id, 0xffddff00, new Position(eff.Radius, 0));

                        foreach (Entity j in Parent.PlayerChunks.HitTest(Position, SightRadius))
                        {
                            if (j is Player k && (k.Client.Account.Effects || k.Equals(this)))
                            {
                                k.Client.Send(@throw);
                            }
                        }

                        Manager.AddTimedAction(1500, () =>
                        {
                            if (placeholder.Parent != null)
                            {
                                if (Parent != null)
                                {
                                    foreach (Entity j in Parent.PlayerChunks.HitTest(Position, SightRadius))
                                    {
                                        if (j is Player k && (k.Client.Account.Effects || k.Equals(this)))
                                        {
                                            k.Client.Send(nova);
                                        }
                                    }
                                    foreach (Entity j in Parent.EntityChunks.HitTest(placeholder.Position, eff.Radius))
                                    {
                                        if (j is Enemy e)
                                        {
                                            e.ApplyPoison(this, new ConditionEffectDesc[0], (int)(eff.TotalDamage / (eff.DurationMS / 1000f)), eff.TotalDamage);
                                        }
                                    }
                                }
                                placeholder.Parent.RemoveEntity(placeholder);
                            }
                        });
Example #24
0
    public ItemDesc GetItem(string name)
    {
        ItemDesc ret = ItemDescList.Find(x => x.Name.Equals(name));

        return(ret);
    }
Example #25
0
        public void Death(Player killer)
        {
#if DEBUG
            if (killer == null)
            {
                throw new Exception("Undefined killer");
            }
#endif

            int baseExp = (int)Math.Ceiling(MaxHP / 10f);
            if (baseExp != 0)
            {
                List <Entity> l;
                foreach (Entity en in l = Parent.PlayerChunks.HitTest(Position, Player.SightRadius))
                {
                    if (!(en is Player player))
                    {
                        continue;
                    }
                    int exp = baseExp;
                    if (exp > Player.GetNextLevelEXP(player.Level) / 10)
                    {
                        exp = Player.GetNextLevelEXP(player.Level) / 10;
                    }
                    if (player.GainEXP(exp))
                    {
                        foreach (Entity p in l)
                        {
                            if (!p.Equals(player))
                            {
                                (p as Player).FameStats.LevelUpAssists++;
                            }
                        }
                    }
                }
            }

            int position = 0;
            foreach (KeyValuePair <int, int> i in DamageStorage.OrderByDescending(k => k.Value))
            {
                Entity en = Parent.GetEntity(i.Key);
                if (en == null)
                {
                    continue;
                }
                Player player = en as Player;

                if (Desc.Quest)
                {
                    player.HealthPotions = Math.Min(Player.MaxPotions, player.HealthPotions + 1);
                    player.MagicPotions  = Math.Min(Player.MaxPotions, player.MagicPotions + 1);
                }
                else
                {
                    if (MathUtils.Chance(.05f))
                    {
                        player.HealthPotions = Math.Min(Player.MaxPotions, player.HealthPotions + 1);
                    }
                    if (MathUtils.Chance(.05f))
                    {
                        player.MagicPotions = Math.Min(Player.MaxPotions, player.MagicPotions + 1);
                    }
                }

                if (!player.Equals(killer))
                {
                    player.FameStats.MonsterAssists++;
                    if (Desc.Cube)
                    {
                        player.FameStats.CubeAssists++;
                    }
                    if (Desc.Oryx)
                    {
                        player.FameStats.OryxAssists++;
                    }
                    if (Desc.God)
                    {
                        player.FameStats.GodAssists++;
                    }
                }

                if (Behavior != null && Behavior.Loots.Count > 0)
                {
                    List <int> items = new List <int>();
                    foreach (Loot l in Behavior.Loots)
                    {
                        float t = Math.Min(1f, i.Value / MaxHP);
                        int   j = l.TryObtainItem(this, player, position, t);
                        if (j != -1)
                        {
                            items.Add(j);
                        }
                        if (items.Count == Container.MaxSlots)
                        {
                            break;
                        }
                    }

                    if (items.Count > 0)
                    {
                        int bagType = 1;
                        for (int k = 0; k < items.Count; k++)
                        {
                            ItemDesc d = Resources.Type2Item[(ushort)items[k]];
                            if (d.BagType > bagType)
                            {
                                bagType = d.BagType;
                            }
                        }

                        if (bagType == 2)
                        {
                            player.FameStats.CyanBags++;
                        }
                        else if (bagType == 3)
                        {
                            player.FameStats.BlueBags++;
                        }
                        else if (bagType == 4)
                        {
                            player.FameStats.WhiteBags++;
                        }

                        Container c = new Container(Container.FromBagType(bagType), player.Id, 40000 * bagType);
                        for (int k = 0; k < items.Count; k++)
                        {
                            Tuple <bool, ItemData> roll = Resources.Type2Item[(ushort)items[k]].Roll();
                            c.Inventory[k] = items[k];
                            c.ItemDatas[k] = roll.Item1 ? (int)roll.Item2 : -1;
                            c.UpdateInventorySlot(k);
                        }
                        Parent.AddEntity(c, Position + MathUtils.Position(0.2f, 0.2f));
                    }
                }

                position++;
            }

            killer.FameStats.MonsterKills++;
            if (Desc.Cube)
            {
                killer.FameStats.CubeKills++;
            }
            if (Desc.Oryx)
            {
                killer.FameStats.OryxKills++;
            }
            if (Desc.God)
            {
                killer.FameStats.GodKills++;
            }

            if (Behavior != null)
            {
                foreach (Behavior b in Behavior.Behaviors)
                {
                    b.Death(this);
                }
                foreach (State s in CurrentStates)
                {
                    foreach (Behavior b in s.Behaviors)
                    {
                        b.Death(this);
                    }
                }
            }

            Dead = true;
            Parent.RemoveEntity(this);
        }
        public void TryShoot(int time, Position pos, float attackAngle, bool ability, int numShots)
        {
            if (!ValidTime(time))
            {
#if DEBUG
                Program.Print(PrintType.Error, "Invalid time for player shoot");
#endif
                Client.Disconnect();
                return;
            }

            if (AwaitingGoto.Count > 0)
            {
                Client.Random.Drop(numShots);
                return;
            }

            if (!ValidMove(time, pos))
            {
#if DEBUG
                Program.Print(PrintType.Error, "Invalid move for player shoot");
#endif
                Client.Disconnect();
                return;
            }

            int startId = NextProjectileId;
            NextProjectileId -= numShots;

            ItemDesc desc = ability ? GetItem(1) : GetItem(0);
            if (desc == null)
            {
#if DEBUG
                Program.Print(PrintType.Error, "Undefined item descriptor");
#endif
                Client.Random.Drop(numShots);
                return;
            }


            if (numShots != desc.NumProjectiles)
            {
#if DEBUG
                Program.Print(PrintType.Error, "Manipulated num shots");
#endif
                Client.Random.Drop(numShots);
                return;
            }

            if (HasConditionEffect(ConditionEffectIndex.Stunned))
            {
#if DEBUG
                Program.Print(PrintType.Error, "Stunned...");
#endif
                Client.Random.Drop(numShots);
                return;
            }

            if (ability)
            {
                if (ShootAEs.TryDequeue(out ushort aeItemType))
                {
                    if (aeItemType != desc.Type)
                    {
                        Client.Random.Drop(numShots);
                        return;
                    }

                    float arcGap   = (desc.ArcGap * MathUtils.ToRadians);
                    float totalArc = arcGap * (numShots - 1);
                    float angle    = attackAngle - (totalArc / 2f);
                    for (int i = 0; i < numShots; i++)
                    {
                        int        damage     = (int)(GetNextDamageSeeded(desc.Projectile.MinDamage, desc.Projectile.MaxDamage, ItemDatas[1]) * GetAttackMultiplier());
                        Projectile projectile = new Projectile(this, desc.Projectile, startId - i, time, angle + (arcGap * i), pos, damage);
                        ShotProjectiles.Add(projectile.Id, projectile);
                    }

                    byte[] packet = GameServer.AllyShoot(Id, desc.Type, attackAngle);
                    foreach (Entity en in Parent.PlayerChunks.HitTest(Position, SightRadius))
                    {
                        if (en is Player player && player.Client.Account.AllyShots && !player.Equals(this))
                        {
                            player.Client.Send(packet);
                        }
                    }

                    FameStats.Shots += numShots;
                }
                else
                {
#if DEBUG
                    Program.Print(PrintType.Error, "Invalid ShootAE");
#endif
                    Client.Random.Drop(numShots);
                }
            }
            else
            {
                if (time > ShotTime + ShotDuration)
                {
                    float arcGap   = (desc.ArcGap * MathUtils.ToRadians);
                    float totalArc = arcGap * (numShots - 1);
                    float angle    = attackAngle - (totalArc / 2f);
                    for (int i = 0; i < numShots; i++)
                    {
                        int        damage     = (int)(GetNextDamageSeeded(desc.Projectile.MinDamage, desc.Projectile.MaxDamage, ItemDatas[0]) * GetAttackMultiplier());
                        Projectile projectile = new Projectile(this, desc.Projectile, startId - i, time, angle + (arcGap * i), pos, damage);
                        ShotProjectiles.Add(projectile.Id, projectile);
                    }

                    byte[] packet = GameServer.AllyShoot(Id, desc.Type, attackAngle);
                    foreach (Entity en in Parent.PlayerChunks.HitTest(Position, SightRadius))
                    {
                        if (en is Player player && player.Client.Account.AllyShots && !player.Equals(this))
                        {
                            player.Client.Send(packet);
                        }
                    }

                    FameStats.Shots += numShots;
                    float rateOfFireMod = ItemDesc.GetStat(ItemDatas[0], ItemData.RateOfFire, ItemDesc.RateOfFireMultiplier);
                    float rateOfFire    = desc.RateOfFire;
                    rateOfFire  *= 1 + rateOfFireMod;
                    ShotDuration = (int)((1f / GetAttackFrequency() * (1f / rateOfFire)) * (1f / RateOfFireThreshold));
                    ShotTime     = time;
                }

                else
                {
#if DEBUG
                    Program.Print(PrintType.Error, "Shot too early, ignored");
#endif
                    Client.Random.Drop(numShots);
                }
            }
        }