Esempio n. 1
0
            protected override async Task OnExecuteAsync()
            {
                var uplayer = (UnturnedUser)Context.Actor;

                if (Context.Parameters.Length > 0)
                {
                    var player = PlayerTool.getSteamPlayer(await Context.Parameters.GetAsync <string>(0));
                    if (player == null)
                    {
                        await uplayer.PrintMessageAsync("Player not found !");

                        return;
                    }

                    if (m_Plugin.Restorer.ContainsKey(uplayer.Player.Player))
                    {
                        m_Plugin.Restorer.Remove(uplayer.Player.Player);
                    }

                    m_Plugin.Restorer.Add(uplayer.Player.Player, player);
                    var inventories = m_Plugin.GetInventories().Where(x => x.PlayerId == player.player.channel.owner.playerID.steamID.ToString()).OrderBy(x => x.Date).ToList();
                    var count       = inventories.Count;
                    await UniTask.SwitchToMainThread();

                    switch (count)
                    {
                    case 0:
                        await uplayer.PrintMessageAsync("The player hasn't any saved inventory !");

                        break;

                    case 1:
                        EffectManager.sendUIEffect(3331, 323, uplayer.SteamId, true);
                        EffectManager.sendUIEffectText(323, uplayer.SteamId, true, "Fecha1", $"{inventories[0].Date.Day}/{inventories[0].Date.Month}/{inventories[0].Date.Year} - {inventories[0].Date.Hour}:{inventories[0].Date.Minute}");
                        EffectManager.sendUIEffectVisibility(323, uplayer.SteamId, true, "2", false);
                        EffectManager.sendUIEffectVisibility(323, uplayer.SteamId, true, "3", false);
                        uplayer.Player.Player.enablePluginWidgetFlag(EPluginWidgetFlags.Modal);
                        break;

                    case 2:
                        EffectManager.sendUIEffect(3331, 323, uplayer.SteamId, true);
                        EffectManager.sendUIEffectText(323, uplayer.SteamId, true, "Fecha1", $"{inventories[0].Date.Day}/{inventories[0].Date.Month}/{inventories[0].Date.Year} - {inventories[0].Date.Hour}:{inventories[0].Date.Minute}");
                        EffectManager.sendUIEffectText(323, uplayer.SteamId, true, "Fecha2", $"{inventories[1].Date.Day}/{inventories[1].Date.Month}/{inventories[1].Date.Year} - {inventories[1].Date.Hour}:{inventories[1].Date.Minute}");
                        uplayer.Player.Player.enablePluginWidgetFlag(EPluginWidgetFlags.Modal);
                        EffectManager.sendUIEffectVisibility(323, uplayer.SteamId, true, "3", false);
                        break;

                    case 3:
                        EffectManager.sendUIEffect(3331, 323, uplayer.SteamId, true);
                        EffectManager.sendUIEffectText(323, uplayer.SteamId, true, "Fecha1", $"{inventories[0].Date.Day}/{inventories[0].Date.Month}/{inventories[0].Date.Year} - {inventories[0].Date.Hour}:{inventories[0].Date.Minute}");
                        EffectManager.sendUIEffectText(323, uplayer.SteamId, true, "Fecha2", $"{inventories[1].Date.Day}/{inventories[1].Date.Month}/{inventories[1].Date.Year} - {inventories[1].Date.Hour}:{inventories[1].Date.Minute}");
                        EffectManager.sendUIEffectText(323, uplayer.SteamId, true, "Fecha3", $"{inventories[2].Date.Day}/{inventories[2].Date.Month}/{inventories[2].Date.Year} - {inventories[2].Date.Hour}:{inventories[2].Date.Minute}");
                        uplayer.Player.Player.enablePluginWidgetFlag(EPluginWidgetFlags.Modal);
                        break;
                    }
                }
                else
                {
                    await uplayer.PrintMessageAsync("usage: /restoreinventory <playerName>");
                }
            }
Esempio n. 2
0
            public Task HandleEventAsync(object?sender, UnturnedPlayerDamagingEvent @event)
            {
                var player = @event.Player;

                if (player.Health <= @event.DamageAmount)
                {
                    var inventories = m_Plugin.GetInventories().Where(x => x.PlayerId == player.SteamId.ToString()).ToList();
                    if (inventories.Count == 3)
                    {
                        var oldest = inventories.OrderBy(x => x.Date).First();
                        m_Plugin.RemoveInventory(oldest);
                    }

                    var cloths = new List <ushort>();

                    cloths.Add(player.Player.clothing.backpack);
                    cloths.Add(player.Player.clothing.glasses);
                    cloths.Add(player.Player.clothing.hat);
                    cloths.Add(player.Player.clothing.mask);
                    cloths.Add(player.Player.clothing.pants);
                    cloths.Add(player.Player.clothing.shirt);
                    cloths.Add(player.Player.clothing.vest);

                    var items = new List <PlayerItem>();

                    for (byte i = 0; i < 7; i++)
                    {
                        byte ic = player.Player.inventory.getItemCount(i);
                        if (ic > 0)
                        {
                            for (byte j = 0; j < ic; j++)
                            {
                                var item = player.Player.inventory.getItem(i, j);
                                if (item != null)
                                {
                                    items.Add(new PlayerItem
                                    {
                                        Id         = item.item.id,
                                        Amount     = item.item.amount,
                                        Durability = item.item.durability,
                                        Metadata   = Convert.ToBase64String(item.item.metadata),
                                        Quality    = item.item.quality,
                                        Rot        = item.rot,
                                        State      = Convert.ToBase64String(item.item.state),
                                        Page       = i,
                                        X          = item.x,
                                        Y          = item.y
                                    });
                                }
                            }
                        }
                    }

                    if (items.Count == 0)
                    {
                        return(Task.CompletedTask);
                    }

                    var playerInventory = new Models.PlayerInventory()
                    {
                        PlayerId = player.SteamId.ToString(),
                        Items    = items,
                        Clothing = cloths,
                        Date     = DateTime.Now
                    };


                    m_Plugin.AddInventory(playerInventory);
                }

                return(Task.CompletedTask);
            }