private void SkinsClose(BasePlayer player) { if (player == null) { return; } ContainerController.Find(player)?.Close(); }
private void OnPlayerLootEnd(PlayerLoot loot) { var player = loot.gameObject.GetComponent <BasePlayer>(); if (player != loot.entitySource) { return; } PrintDebug("OnLootEntityEnd: Closing container"); ContainerController.Find(player)?.Close(); }
private object CanLootPlayer(BasePlayer looter, Object target) { if (looter != target) { return(null); } var container = ContainerController.Find(looter); if (container == null || !container.IsOpened) { return(null); } return(true); }
private object CanMoveItem(Item item, PlayerInventory playerLoot, uint targetContainerId, int slot, int amount) { PrintDebug( $"Move {item.info.shortname} ({item.amount}) from {item.parent?.uid ?? 0} to {targetContainerId} in {slot} ({amount})"); if (item.parent?.uid == targetContainerId) { PrintDebug("Move Ignoring same containers"); return(null); } var containerFrom = ContainerController.Find(item.parent); var containerTo = ContainerController.Find(targetContainerId); return(CanMoveItemFrom(containerFrom, item, playerLoot, slot, amount) ?? CanMoveItemTo(containerTo, item, playerLoot, slot, amount)); }
private object CanMoveItem(Item item, PlayerInventory playerLoot, uint targetContainerId, int slot, int amount) { var containerFrom = ContainerController.Find(item.parent); var containerTo = ContainerController.Find(targetContainerId); if ((containerFrom ?? containerTo) == null) { return(null); } PrintDebug($"CanMoveItem: {item.info.shortname} ({item.amount}) from {item.parent?.uid ?? 0} to {targetContainerId} in {slot} ({amount})"); if (item.parent?.uid == targetContainerId) { PrintDebug("// CanMoveItem: Preventing same containers"); return(false); } return(CanMoveItemTo(containerTo, item, slot, amount)); }
private void OnItemRemovedFromContainer(ItemContainer itemContainer, Item item) { if (item.parentItem != null) { return; } var player = itemContainer.entityOwner as BasePlayer; var container = ContainerController.Find(itemContainer); if (container == null || player == null || container.Owner != player) { return; } PrintDebug($"OnItemRemovedFromContainer {item.info.shortname} {item.position}"); container.SetupContent(item); container.Clear(); }
private void OnItemRemovedFromContainer(ItemContainer itemContainer, Item item) { if (item.parentItem != null) { return; } var container = ContainerController.Find(itemContainer); var player = itemContainer.entityOwner as BasePlayer; if (player == null || container == null) { return; } PrintDebug($"OnItemRemovedFromContainer: {item.info.shortname} (slot {item.position})"); container.SetupContent(item); Interface.CallHook("OnItemSkinChanged", player, item); container.Clear(); }
private void CommandSkin(IPlayer player, string command, string[] args) { PrintDebug("Executed Skin command"); if (!CanUse(player)) { PrintDebug("Not allowed"); player.Reply(GetMsg("Not Allowed", player.Id)); return; } if (args.Length == 0) { args = new[] { "show" } } ; // :P strange yeah var isAdmin = player.IsServer || CanUseAdmin(player); var basePlayer = player.Object as BasePlayer; var isPlayer = basePlayer != null; PrintDebug($"Arguments: {string.Join(" ", args)}"); PrintDebug($"Is Admin: {isAdmin} : Is Player: {isPlayer}"); switch (args[0].ToLower()) { case "_tech-update": { int page; if (args.Length != 2 || !isPlayer || !int.TryParse(args[1], out page)) { break; } ContainerController.Find(basePlayer)?.UpdateContent(page); break; } case "show": case "s": { if (!isPlayer) { PrintDebug("Not a player"); player.Reply(GetMsg("Cannot Use", player.Id)); break; } var container = ContainerController.Find(basePlayer); if (container == null || !container.CanShow()) { PrintDebug("Cannot show container or container not found"); player.Reply(GetMsg("Cannot Use", player.Id)); break; } basePlayer.Invoke(container.Show, 0.5f); break; } case "add": case "a": { if (args.Length != 3) { goto default; } if (!isAdmin) { PrintDebug("Not an admin"); player.Reply(GetMsg("Not Allowed", player.Id)); break; } var shortname = args[1]; ulong skin; if (!ulong.TryParse(args[2], out skin)) { PrintDebug("Invalid skin"); player.Reply(GetMsg("Incorrect Skin", player.Id)); break; } LoadConfig(); var skinData = Configuration.SkinItem.Find(shortname); if (skinData == null) { skinData = new Configuration.SkinItem { Shortname = shortname }; _config.Skins.Add(skinData); } if (skinData.Skins.Contains(skin)) { PrintDebug("Skin already exists"); player.Reply(GetMsg("Skin Already Exists", player.Id)); break; } skinData.Skins.Add(skin); player.Reply(GetMsg("Skin Added", player.Id)); SaveConfig(); PrintDebug("Added skin"); break; } case "remove": case "delete": case "r": case "d": { if (args.Length != 3) { goto default; } if (!isAdmin) { PrintDebug("Not an admin"); player.Reply(GetMsg("Not Allowed", player.Id)); break; } var shortname = args[1]; ulong skin; if (!ulong.TryParse(args[2], out skin)) { PrintDebug("Invalid skin"); player.Reply(GetMsg("Incorrect Skin", player.Id)); break; } LoadConfig(); var skinData = Configuration.SkinItem.Find(shortname); int index; if (skinData == null || (index = skinData.Skins.IndexOf(skin)) == -1) { PrintDebug("Skin doesnt exist"); player.Reply(GetMsg("Skin Does Not Exist", player.Id)); break; } skinData.Skins.RemoveAt(index); player.Reply(GetMsg("Skin Removed", player.Id)); SaveConfig(); PrintDebug("Removed skin"); break; } case "get": case "g": { if (!isPlayer) { PrintDebug("Not a player"); player.Reply(GetMsg("Cannot Use", player.Id)); break; } var item = basePlayer.GetActiveItem(); if (item == null || !item.IsValid()) { PrintDebug("Invalid item"); player.Reply(GetMsg("Skin Get No Item", player.Id)); break; } player.Reply(GetMsg("Skin Get Format", player.Id).Replace("{shortname}", item.info.shortname) .Replace("{id}", item.skin.ToString())); break; } default: // and "help", and all other args { PrintDebug("Unknown command"); player.Reply(GetMsg(isAdmin ? "Admin Help" : "Help", player.Id)); break; } } }