Ejemplo n.º 1
0
        public static void Spawn(SharpBridge.Player player, object[] param)
        {
            uint weapon = (uint)param[0];

            if (weapon < 1 || weapon == 6 || weapon == 8 || weapon > 18)
            {
                player.sendMsg($"Weapon {weapon} is invalid. Use 1-5, 7, 9-18", ChatColor.ERROR);
                return;
            }

            Models.ItemTypesEF wClass = Game.ItemTypesManager.GetWeaponFromGameWeapon((byte)weapon);
            if (wClass == null)
            {
                player.sendMsg($"Not a database weapon", ChatColor.ERROR);
                return;
            }

            Game.Account acc = Game.AccountManager.Get(player.getID());
            acc.insertItem((short)weapon, 1, false);
            acc.insertItem(wClass.weapon.ammoItem, 200);

            Models.ItemEF bullets = acc.getItem(wClass.weapon.ammoItem);
            if (bullets == null)
            {
                return;                  //Overkill almost
            }
            player.giveWeapon(weapon, (uint)bullets.amount);
        }
Ejemplo n.º 2
0
 public void insertItem(short model, short amount, bool incrementIfExists = true)
 {
     Models.ItemEF item = user.entity.items.Where(i => i.type == model).FirstOrDefault();
     if (item == null)
     {
         item = new Models.ItemEF
         {
             entity   = user.entity,
             type     = model,
             amount   = amount,
             fk       = user.entity.id,
             mustSave = false
         };
         user.entity.items.Add(item);
     }
     else if (item.amount != amount && incrementIfExists)
     {
         item.amount   = amount;
         item.mustSave = true;
     }
 }
Ejemplo n.º 3
0
        public static void Login(SharpBridge.Player player, object[] param)
        {
            try
            {
                string gameNick = player.getNick();
                if (Game.AccountManager.GetByName(ref gameNick) != null)
                {
                    player.sendMsg("This account is already being used", ChatColor.ERROR);
                    return;
                }

                string user = gameNick.ToLower();
                string pass = ((string)param[0]).ToLower();
                using (Repositories.UserRepository accs = new Repositories.UserRepository())
                {
                    Models.UserEF acc = accs.users.Where(i => i.name == user).
                                        Include(i => i.entity).Include(i => i.entity.items).FirstOrDefault();

                    if (acc == null)
                    {
                        player.sendMsg($"Account '{player.getNick()}' doesn't exist", ChatColor.ERROR);
                        return;
                    }
                    else if (acc.password.ToLower() != Services.Hashing.SHA2(ref pass))
                    {
                        player.sendMsg("Wrong password", ChatColor.ERROR);
                        return;
                    }

                    Console.WriteLine(JsonConvert.SerializeObject(acc));

                    Game.Account playerAccount = new Game.Account(acc);
                    Game.AccountManager.Add(player.getID(), playerAccount);

                    playerAccount.setClothesFromString(player);
                    player.setPos(playerAccount.getPos());
                    player.setHealth(acc.hp);
                    player.setArmor(acc.armor);
                    player.setFrozen(false);
                    player.cam_setPos(null, 1);
                    player.cam_attachOnPlayer(-1);
                    player.setWorld(1);
                    // Colors "Welcome back" green and the player’s name orange for 5 seconds
                    player.drawInfoText($"~g~Welcome back~w~, ~COL_NET_13~'{player.getNick()}'~w~!", 5000);

                    List <short> givenAmmoTypes = new List <short>();
                    foreach (var item in acc.entity.items)
                    {
                        Models.ItemTypesEF typ = Game.ItemTypesManager.GetItemTypeByItem(item);
                        if (typ.weapon != null)
                        {
                            Console.WriteLine($"{item.type} is a weapon");
                            Models.ItemEF ammo = acc.entity.items.Where(j => j.type == typ.weapon.ammoItem).FirstOrDefault();
                            if (ammo == null || givenAmmoTypes.Count(j => j == ammo.type) != 0)
                            {
                                continue;
                            }
                            Console.WriteLine("Ammo found");
                            givenAmmoTypes.Add(ammo.type);
                            player.giveWeapon((uint)item.type, (uint)ammo.amount);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }