Exemple #1
0
        private void Init(ClientProcessor psr)
        {
            this.psr = psr;
            acc      = psr.Account;
            var vaultChestPosition = new List <IntPoint>();
            var spawn = new IntPoint(0, 0);

            var w = Map.Width;
            var h = Map.Height;

            for (var y = 0; y < h; y++)
            {
                for (var x = 0; x < w; x++)
                {
                    var tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                    {
                        spawn = new IntPoint(x, y);
                    }
                    else if (tile.Region == TileRegion.Vault)
                    {
                        vaultChestPosition.Add(new IntPoint(x, y));
                    }
                }
            }
            vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                        (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                        (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            var chests = psr.Account.Vault.Chests;

            foreach (VaultChest t in chests)
            {
                var con = new Container(0x0504, null, false);
                var inv =
                    t.Items.Select(
                        _ =>
                        _ == -1
                                ? null
                                : (XmlDatas.ItemDescs.ContainsKey((short)_) ? XmlDatas.ItemDescs[(short)_] : null))
                    .ToArray();
                for (var j = 0; j < 8; j++)
                {
                    con.Inventory[j] = inv[j];
                }
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                _vaultChests[new Tuple <Container, VaultChest>(con, t)] = con.UpdateCount;
            }
            foreach (var i in vaultChestPosition)
            {
                var x = new SellableObject(0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }
Exemple #2
0
        private void InitVault(Client client)
        {
            AccountId = client.Account.AccountId;
            OwnerName = client.Account.Name;

            List <IntPoint> vaultChestPosition = new List <IntPoint>();
            IntPoint        spawn = new IntPoint(0, 0);

            int w = Map.Width;
            int h = Map.Height;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    var tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                    {
                        spawn = new IntPoint(x, y);
                    }
                    else if (tile.Region == TileRegion.Vault)
                    {
                        vaultChestPosition.Add(new IntPoint(x, y));
                    }
                }
            }
            vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                        (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                        (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            var chests = client.Account.Vault.Chests;

            foreach (VaultChest t in chests)
            {
                Container con = new Container(client.Manager, 0x0504, null, false);
                var       inv = t.Items.Select(_ => _ == -1 ? null : client.Manager.GameData.Items[(ushort)_]).ToArray();
                for (int j = 0; j < 8; j++)
                {
                    con.Inventory[j] = inv[j];
                }
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                vaultChests[new Tuple <Container, VaultChest>(con, t)] = con.UpdateCount;
            }
            foreach (var i in vaultChestPosition)
            {
                SellableObject x = new SellableObject(client.Manager, 0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }
Exemple #3
0
        private void InitVault()
        {
            var vaultChestPosition = new List <IntPoint>();
            var spawn = new IntPoint(0, 0);

            int w = Map.Width;
            int h = Map.Height;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    WmapTile tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                    {
                        spawn = new IntPoint(x, y);
                    }
                    else if (tile.Region == TileRegion.Vault)
                    {
                        vaultChestPosition.Add(new IntPoint(x, y));
                    }
                }
            }
            vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                        (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                        (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            List <VaultChest> chests = client.Account.Vault.Chests;

            for (int i = 0; i < chests.Count; i++)
            {
                var    con = new Container(client.Manager, 0x0504, null, false);
                Item[] inv =
                    chests[i].Items.Select(_ => _ == 0xffff ? null : client.Manager.GameData.Items[_]).ToArray();
                ItemData[] dats = chests[i].Datas;
                for (int j = 0; j < 8; j++)
                {
                    con.Inventory[j]      = inv[j];
                    con.Inventory.Data[j] = dats[j];
                }
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                vaultChests[new Tuple <Container, VaultChest>(con, chests[i])] = con.UpdateCount;
            }
            foreach (IntPoint i in vaultChestPosition)
            {
                var x = new SellableObject(client.Manager, 0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }
Exemple #4
0
        void Init(ClientProcessor psr)
        {
            this.psr = psr;
            this.acc = psr.Account;
            List <IntPoint> vaultChestPosition = new List <IntPoint>();
            IntPoint        spawn = new IntPoint(0, 0);

            int w = Map.Width;
            int h = Map.Height;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    var tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                    {
                        spawn = new IntPoint(x, y);
                    }
                    else if (tile.Region == TileRegion.Vault)
                    {
                        vaultChestPosition.Add(new IntPoint(x, y));
                    }
                }
            }
            vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                        (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                        (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            var chests = psr.Account.Vault.Chests;

            for (int i = 0; i < chests.Count; i++)
            {
                Container con = new Container(0x0504, null, false);
                var       inv = chests[i].Items.Select(_ => _ == -1 ? null : (XmlDatas.ItemDescs.ContainsKey((short)_) ? XmlDatas.ItemDescs[(short)_] : null)).ToArray();
                for (int j = 0; j < 8; j++)
                {
                    con.Inventory[j] = inv[j];
                }
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f); //if getting debugger error here, check database to see if someones account has an extra vault. Delete the line.
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                vaultChests[new Tuple <Container, VaultChest>(con, chests[i])] = con.UpdateCount;
            }
            foreach (var i in vaultChestPosition)
            {
                SellableObject x = new SellableObject(0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }
        void Handle(Player player, int objId)
        {
            if (player.Owner == null)
            {
                return;
            }

            SellableObject obj = player.Owner.GetEntity(objId) as SellableObject;

            if (obj != null)
            {
                obj.Buy(player);
            }
        }
Exemple #6
0
        private void InitVault()
        {
            List <IntPoint> vaultChestPosition = new List <IntPoint>();
            IntPoint        spawn = new IntPoint(0, 0);

            int w = Map.Width;
            int h = Map.Height;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    var tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                    {
                        spawn = new IntPoint(x, y);
                    }
                    else if (tile.Region == TileRegion.Vault)
                    {
                        vaultChestPosition.Add(new IntPoint(x, y));
                    }
                }
            }
            vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                        (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                        (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            dbVault = new DbVault(client.Account);
            for (int i = 0; i < client.Account.VaultCount; i++)
            {
                Container con = new Container(client.Manager, 0x0504, null, false);
                var       inv = dbVault[i].Select(x => x == 0xffff ? null : client.Manager.GameData.Items[(ushort)x]).ToArray();
                for (int j = 0; j < 8; j++)
                {
                    con.Inventory[j] = inv[j];
                }
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                vaultChests[Tuple.Create(con, i)] = con.UpdateCount;
            }
            foreach (var i in vaultChestPosition)
            {
                SellableObject x = new SellableObject(client.Manager, 0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }
Exemple #7
0
 protected override void HandlePacket(Client client, BuyPacket packet)
 {
     client.Manager.Logic.AddPendingAction(t =>
     {
         if (client.Player.Owner == null)
         {
             return;
         }
         SellableObject obj = client.Player.Owner.GetEntity(packet.ObjectId) as SellableObject;
         if (obj != null)
         {
             obj.Buy(client.Player);
         }
     }, PendingPriority.Networking);
 }
Exemple #8
0
        private void Init(Client psr)
        {
            if (psr == null)
            {
                return;
            }
            AccountId       = psr.Account.AccountId;
            PlayerOwnerName = psr.Account.Name;

            List <IntPoint> vaultChestPosition = new List <IntPoint>();
            List <IntPoint> giftChestPosition  = new List <IntPoint>();
            IntPoint        spawn = new IntPoint(0, 0);

            int w = Map.Width;
            int h = Map.Height;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    WmapTile tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                    {
                        spawn = new IntPoint(x, y);
                    }
                    else if (tile.Region == TileRegion.Vault)
                    {
                        vaultChestPosition.Add(new IntPoint(x, y));
                    }
                    else if (tile.Region == TileRegion.Gifting_Chest)
                    {
                        giftChestPosition.Add(new IntPoint(x, y));
                    }
                }
            }
            vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                        (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                        (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            if (psr.Account.Gifts != null)
            {
                List <GiftChest> giftChests = new List <GiftChest>();
                GiftChest        c          = new GiftChest
                {
                    Items = new List <Item>(8)
                };
                bool  wasLastElse = false;
                int[] gifts       = psr.Account.Gifts.ToArray();
                gifts.Shuffle();
                for (int i = 0; i < gifts.Count(); i++)
                {
                    if (GameServer.Manager.GameData.Items.ContainsKey((ushort)gifts[i]))
                    {
                        if (c.Items.Count < 8)
                        {
                            c.Items.Add(GameServer.Manager.GameData.Items[(ushort)gifts[i]]);
                            wasLastElse = false;
                        }
                        else
                        {
                            giftChests.Add(c);
                            c = new GiftChest
                            {
                                Items = new List <Item>(8)
                            };
                            c.Items.Add(GameServer.Manager.GameData.Items[(ushort)gifts[i]]);
                            wasLastElse = true;
                        }
                    }
                }
                if (!wasLastElse)
                {
                    giftChests.Add(c);
                }

                foreach (GiftChest chest in giftChests)
                {
                    if (giftChestPosition.Count == 0)
                    {
                        break;
                    }
                    while (chest.Items.Count < 8)
                    {
                        chest.Items.Add(null);
                    }
                    OneWayContainer con = new OneWayContainer(0x0744, null, false);
                    List <Item>     inv = chest.Items;
                    for (int j = 0; j < 8; j++)
                    {
                        con.Inventory[j] = inv[j];
                    }
                    con.Move(giftChestPosition[0].X + 0.5f, giftChestPosition[0].Y + 0.5f);
                    EnterWorld(con);
                    giftChestPosition.RemoveAt(0);
                }
            }
            dbVault = new DbVault(psr.Account);
            for (int i = 0; i < psr.Account.VaultCount; i++)
            {
                if (vaultChestPosition.Count == 0)
                {
                    break;
                }
                Container con = new Container(0x0504, null, false);
                var       inv = dbVault[i].Select(_ => _ == -1 ? null : (GameServer.Manager.GameData.Items.ContainsKey((ushort)_) ? GameServer.Manager.GameData.Items[(ushort)_] : null)).ToArray();
                for (int j = 0; j < 8; j++)
                {
                    con.Inventory[j] = inv[j];
                }
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                _vaultChests[Tuple.Create(con, i)] = con.UpdateCount;
            }

            foreach (IntPoint i in giftChestPosition)
            {
                GameObject x = new GameObject(0x0743, null, true, false, false);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }

            foreach (IntPoint i in vaultChestPosition)
            {
                SellableObject x = new SellableObject(0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }
Exemple #9
0
        private void Init(Client psr)
        {
            AccountId       = psr.Account.AccountId;
            PlayerOwnerName = psr.Account.Name;

            List <IntPoint> vaultChestPosition = new List <IntPoint>();
            List <IntPoint> giftChestPosition  = new List <IntPoint>();
            IntPoint        spawn = new IntPoint(0, 0);

            int w = Map.Width;
            int h = Map.Height;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    WmapTile tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                    {
                        spawn = new IntPoint(x, y);
                    }
                    else if (tile.Region == TileRegion.Vault)
                    {
                        vaultChestPosition.Add(new IntPoint(x, y));
                    }
                    else if (tile.Region == TileRegion.Gifting_Chest)
                    {
                        giftChestPosition.Add(new IntPoint(x, y));
                    }
                }
            }
            vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                        (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                        (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            List <VaultChest> chests = psr.Account.Vault.Chests;

            if (psr.Account.Gifts != null)
            {
                List <GiftChest> giftChests = new List <GiftChest>();
                GiftChest        c          = new GiftChest();
                c.Items = new List <Item>(8);
                bool  wasLastElse = false;
                int[] gifts       = psr.Account.Gifts.ToArray();
                gifts.Shuffle();
                using (Database db = new Database())
                {
                    for (int i = 0; i < gifts.Count(); i++)
                    {
                        Item newGift = db.getSerialInfo(gifts[i], Manager.GameData);
                        if (c.Items.Count < 8)
                        {
                            c.Items.Add(newGift);
                            wasLastElse = false;
                        }
                        else
                        {
                            giftChests.Add(c);
                            c       = new GiftChest();
                            c.Items = new List <Item>(8);
                            c.Items.Add(newGift);
                            wasLastElse = true;
                        }
                    }
                }
                if (!wasLastElse)
                {
                    giftChests.Add(c);
                }

                foreach (GiftChest chest in giftChests)
                {
                    if (giftChestPosition.Count == 0)
                    {
                        break;
                    }
                    while (chest.Items.Count < 8)
                    {
                        chest.Items.Add(null);
                    }
                    OneWayContainer con = new OneWayContainer(Manager, 0x0744, null, false);
                    List <Item>     inv = chest.Items;
                    for (int j = 0; j < 8; j++)
                    {
                        con.Inventory[j] = inv[j];
                    }
                    con.Move(giftChestPosition[0].X + 0.5f, giftChestPosition[0].Y + 0.5f);
                    EnterWorld(con);
                    giftChestPosition.RemoveAt(0);
                }
            }

            foreach (VaultChest t in chests)
            {
                if (vaultChestPosition.Count == 0)
                {
                    break;
                }
                Container con = new Container(Manager, 0x0504, null, false);
                Item[]    inv;
                using (Database db = new Database())
                {
                    inv = db.getSerialInfo(t.Items, Manager.GameData);
                };
                for (int j = 0; j < 8; j++)
                {
                    con.Inventory[j] = inv[j];
                }
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                _vaultChests[new Tuple <Container, VaultChest>(con, t)] = con.UpdateCount;
            }

            foreach (IntPoint i in giftChestPosition)
            {
                StaticObject x = new StaticObject(Manager, 0x0743, null, true, false, false);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }

            foreach (IntPoint i in vaultChestPosition)
            {
                SellableObject x = new SellableObject(Manager, 0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }
Exemple #10
0
        private void Init(string accId)
        {
            Manager.Database.DoActionAsync(db =>
            {
                AccountId = accId;

                MySqlCommand cmd = db.CreateQuery();
                cmd.CommandText  = "SELECT name FROM accounts WHERE id=@accId";
                cmd.Parameters.AddWithValue("@accId", accId);
                using (MySqlDataReader rdr = cmd.ExecuteReader())
                    while (rdr.Read())
                    {
                        PlayerOwnerName = rdr.GetString("name");
                    }

                List <IntPoint> vaultChestPosition = new List <IntPoint>();
                IntPoint spawn = new IntPoint(0, 0);

                int w = Map.Width;
                int h = Map.Height;
                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        WmapTile tile = Map[x, y];
                        if (tile.Region == TileRegion.Spawn)
                        {
                            spawn = new IntPoint(x, y);
                        }
                        else if (tile.Region == TileRegion.Vault)
                        {
                            vaultChestPosition.Add(new IntPoint(x, y));
                        }
                    }
                }
                vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                            (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                            (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

                List <VaultChest> chests = new List <VaultChest>();

                cmd             = db.CreateQuery();
                cmd.CommandText = "SELECT items, chestId FROM vaults WHERE accId=@accId";
                cmd.Parameters.AddWithValue("@accId", accId);
                using (MySqlDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        chests.Add(new VaultChest
                        {
                            _Items  = rdr.GetString("items"),
                            ChestId = rdr.GetInt32("chestId")
                        });
                    }
                }

                foreach (VaultChest t in chests)
                {
                    Container con = new Container(Manager, 0x0504, null, false);
                    Item[] inv    = db.getSerialInfo(t.Items, Manager.GameData);
                    for (int j = 0; j < 8; j++)
                    {
                        con.Inventory[j] = inv[j];
                    }
                    con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                    EnterWorld(con);
                    vaultChestPosition.RemoveAt(0);

                    _vaultChests[new Tuple <Container, VaultChest>(con, t)] = con.UpdateCount;
                }
                foreach (IntPoint i in vaultChestPosition)
                {
                    SellableObject x = new SellableObject(Manager, 0x0505);
                    x.Move(i.X + 0.5f, i.Y + 0.5f);
                    EnterWorld(x);
                }
            });
        }
Exemple #11
0
    private void Update()
    {
        myPos   = new Vector3(transform.position.x, 0, transform.position.z);
        destPos = new Vector3(destination.position.x, 0, destination.position.z);
        switch (currentState)
        {
        case NpcStates.BUYSTATION:
            if (Vector3.Distance(myPos, destPos) < destinationRange)
            {
                // When npc is close enough to the station point, make it look at the items.
                ChangeState(NpcStates.CHECKING);
            }
            break;

        case NpcStates.CHECKING:
            // Countdown for when npc the stops looking at items.
            curLookTime -= Time.deltaTime;
            if (curLookTime < 0)
            {
                int choice = Random.Range(0, 2);
                manager.buyStations[destinationStation].standingPoints[destinationPoint].isOccupied = false;
                if (choice == 0 && curStationChange < maxStationChange)
                {
                    // Pick another station to look at.
                    ChangeState(NpcStates.BUYSTATION);
                    curStationChange++;
                }
                else
                {
                    if (purpose == NpcGoals.BUY)
                    {
                        // Setting the Item which will be bought.
                        BuyStation b = manager.buyStations[destinationStation];
                        desiredItem = b.sellableObjects[Random.Range(0, b.sellableObjects.Length)];

                        // Go to the next state if is done looking around.
                        ChangeState(NpcStates.COUNTER);
                    }
                    else
                    {
                        // Was looking around so will leave.
                        ChangeState(NpcStates.LEAVE);
                    }
                }
                curLookTime = Random.Range(minLookTime, maxLookTime);
            }
            break;

        case NpcStates.COUNTER:
            if (Vector3.Distance(myPos, destPos) < destinationRange)
            {
                ChangeState(NpcStates.CHECKOUT);
            }
            break;

        case NpcStates.CHECKOUT:
            break;

        case NpcStates.LEAVE:
            break;

        case NpcStates.TALK:
            break;

        default:
            break;
        }
    }
Exemple #12
0
        private void Init(Client psr)
        {
            AccountId       = psr.Account.AccountId;
            PlayerOwnerName = psr.Account.Name;

            List <IntPoint> vaultChestPosition = new List <IntPoint>();
            List <IntPoint> giftChestPosition  = new List <IntPoint>();
            IntPoint        spawn = new IntPoint(0, 0);

            int w = Map.Width;
            int h = Map.Height;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    WmapTile tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                    {
                        spawn = new IntPoint(x, y);
                    }
                    else if (tile.Region == TileRegion.Vault)
                    {
                        vaultChestPosition.Add(new IntPoint(x, y));
                    }
                    else if (tile.Region == TileRegion.Gifting_Chest)
                    {
                        giftChestPosition.Add(new IntPoint(x, y));
                    }
                }
            }
            vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                        (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                        (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            List <VaultChest> chests = psr.Account.Vault.Chests;



            foreach (VaultChest t in chests)
            {
                if (vaultChestPosition.Count == 0)
                {
                    break;
                }
                Container con = new Container(Manager, 0x0504, null, false);
                Item[]    inv =
                    t.Items.Select(
                        _ =>
                        _ == -1
                                ? null
                                : (Manager.GameData.Items.ContainsKey((ushort)_)
                                    ? Manager.GameData.Items[(ushort)_]
                                    : null))
                    .ToArray();
                for (int j = 0; j < 8; j++)
                {
                    con.Inventory[j] = inv[j];
                }
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                _vaultChests[new Tuple <Container, VaultChest>(con, t)] = con.UpdateCount;
            }

            foreach (IntPoint i in giftChestPosition)
            {
                StaticObject x = new StaticObject(Manager, 0x0743, null, true, false, false);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }

            foreach (IntPoint i in vaultChestPosition)
            {
                SellableObject x = new SellableObject(Manager, 0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }
Exemple #13
0
        private void InitVault()
        {
            var             vaultChestPosition = new List <IntPoint>();
            List <IntPoint> giftChestPosition  = new List <IntPoint>();
            var             spawn = new IntPoint(0, 0);

            int w = Map.Width;
            int h = Map.Height;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    WmapTile tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                    {
                        spawn = new IntPoint(x, y);
                    }
                    else if (tile.Region == TileRegion.Vault)
                    {
                        vaultChestPosition.Add(new IntPoint(x, y));
                    }
                    else if (tile.Region == TileRegion.Gifting_Chest)
                    {
                        giftChestPosition.Add(new IntPoint(x, y));
                    }
                }
            }
            vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                        (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                        (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            List <VaultChest> chests = client.Account.Vault.Chests;

            if (client.Account.Gifts != null)
            {
                List <GiftChest> giftChests = new List <GiftChest>();
                GiftChest        c          = new GiftChest();
                c.Items = new List <Item>(8);
                bool  wasLastElse = false;
                int[] gifts       = client.Account.Gifts.ToArray();
                gifts.Shuffle();
                for (int i = 0; i < gifts.Count(); i++)
                {
                    if (Manager.GameData.Items.ContainsKey((ushort)gifts[i]))
                    {
                        if (c.Items.Count < 8)
                        {
                            c.Items.Add(Manager.GameData.Items[(ushort)gifts[i]]);
                            wasLastElse = false;
                        }
                        else
                        {
                            giftChests.Add(c);
                            c       = new GiftChest();
                            c.Items = new List <Item>(8);
                            c.Items.Add(Manager.GameData.Items[(ushort)gifts[i]]);
                            wasLastElse = true;
                        }
                    }
                }
                if (!wasLastElse)
                {
                    giftChests.Add(c);
                }

                foreach (GiftChest chest in giftChests)
                {
                    if (giftChestPosition.Count == 0)
                    {
                        break;
                    }
                    while (chest.Items.Count < 8)
                    {
                        chest.Items.Add(null);
                    }
                    OneWayContainer con = new OneWayContainer(Manager, 0x0744, null, false);
                    List <Item>     inv = chest.Items;
                    for (int j = 0; j < 8; j++)
                    {
                        con.Inventory[j] = inv[j];
                    }
                    con.Move(giftChestPosition[0].X + 0.5f, giftChestPosition[0].Y + 0.5f);
                    EnterWorld(con);
                    giftChestPosition.RemoveAt(0);
                }
            }

            for (int i = 0; i < chests.Count; i++)
            {
                var    con = new Container(client.Manager, 0x0504, null, false);
                Item[] inv =
                    chests[i].Items.Select(_ => _ == 0xffff ? null : client.Manager.GameData.Items[_]).ToArray();
                ItemData[] dats = chests[i].Datas;
                for (int j = 0; j < 8; j++)
                {
                    con.Inventory[j]      = inv[j];
                    con.Inventory.Data[j] = dats[j];
                }
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                vaultChests[new Tuple <Container, VaultChest>(con, chests[i])] = con.UpdateCount;
            }

            foreach (IntPoint i in giftChestPosition)
            {
                StaticObject x = new StaticObject(Manager, 0x0743, null, true, false, false);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }

            foreach (IntPoint i in vaultChestPosition)
            {
                var x = new SellableObject(client.Manager, 0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }
Exemple #14
0
        private void InitVault(int accId)
        {
            Manager.Database.AddDatabaseOperation(db =>
            {
                AccountId = accId;

                var cmd         = db.CreateQuery();
                cmd.CommandText = "SELECT name FROM accounts WHERE id=@accId";
                cmd.Parameters.AddWithValue("@accId", accId);
                using (var rdr = cmd.ExecuteReader())
                    while (rdr.Read())
                    {
                        OwnerName = rdr.GetString("name");
                    }

                var vaultChestPosition = new List <IntPoint>();
                var spawn = new IntPoint(0, 0);

                var w = Map.Width;
                var h = Map.Height;
                for (var y = 0; y < h; y++)
                {
                    for (var x = 0; x < w; x++)
                    {
                        var tile = Map[x, y];
                        if (tile.Region == TileRegion.Spawn)
                        {
                            spawn = new IntPoint(x, y);
                        }
                        else if (tile.Region == TileRegion.Vault)
                        {
                            vaultChestPosition.Add(new IntPoint(x, y));
                        }
                    }
                }
                vaultChestPosition.Sort((x, y) => Comparer <int> .Default.Compare(
                                            (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                                            (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

                var chests = new List <VaultChest>();

                cmd             = db.CreateQuery();
                cmd.CommandText = "SELECT items, chestId FROM vaults WHERE accId=@accId";
                cmd.Parameters.AddWithValue("@accId", accId);
                using (var rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        chests.Add(new VaultChest
                        {
                            _Items  = rdr.GetString("items"),
                            ChestId = rdr.GetInt32("chestId")
                        });
                    }
                }
                foreach (var t in chests)
                {
                    var con = new Container(client.Manager, 0x0504, null, false);
                    var inv = t.Items.Select(_ => _ == -1 ? null : client.Manager.GameData.Items[(ushort)_]).ToArray();
                    for (var j = 0; j < 8; j++)
                    {
                        con.Inventory[j] = inv[j];
                    }
                    con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                    EnterWorld(con);
                    vaultChestPosition.RemoveAt(0);

                    vaultChests[new Tuple <Container, VaultChest>(con, t)] = con.UpdateCount;
                }
                foreach (var i in vaultChestPosition)
                {
                    var x = new SellableObject(client.Manager, 0x0505);
                    x.Move(i.X + 0.5f, i.Y + 0.5f);
                    EnterWorld(x);
                }
            });
        }