Beispiel #1
0
 public ItemEntity(ItemStack stack, Region tregion)
     : base(stack.Model, tregion)
 {
     Stack = stack;
     SetMass(Math.Max(1f, stack.Weight) * stack.Count);
     CGroup = CollisionUtil.Item;
 }
Beispiel #2
0
 public override Entity Create(Region tregion, BsonDocument doc)
 {
     ItemStack stack = new ItemStack(doc["it_stack"].AsBinary, tregion.TheServer);
     ItemEntity ent = new ItemEntity(stack, tregion);
     ent.ApplyPhysicsData(doc);
     return ent;
 }
Beispiel #3
0
 public override Entity Create(Region tregion, BsonDocument doc)
 {
     ItemStack it = new ItemStack(doc["mb_item"].AsBinary, tregion.TheServer);
     MusicBlockEntity mbe = new MusicBlockEntity(tregion, it, Location.Zero);
     mbe.SetMaxHealth((double)doc["mb_maxhealth"].AsDouble);
     mbe.SetHealth((double)doc["mb_health"].AsDouble);
     return mbe;
 }
Beispiel #4
0
 // TODO: Heal with time?
 public MusicBlockEntity(Region tregion, ItemStack orig, Location pos)
     : base("mapobjects/customblocks/musicblock", tregion)
 {
     Original = orig;
     SetMass(0);
     SetPosition(pos.GetBlockLocation() + new Location(0.5));
     SetOrientation(Quaternion.Identity);
 }
Beispiel #5
0
 public SetItemPacketOut(int spot, ItemStack item)
 {
     UsageType = NetUsageType.GENERAL;
     ID = ServerToClientPacket.SET_ITEM;
     byte[] itemdat = item.ToBytes();
     Data = new byte[4 + itemdat.Length];
     Utilities.IntToBytes(spot).CopyTo(Data, 0);
     itemdat.CopyTo(Data, 4);
 }
Beispiel #6
0
 public StaticBlockEntity(Region tregion, ItemStack orig, Location pos)
     : base(tregion)
 {
     SetMass(0);
     CGroup = CollisionUtil.Item;
     Original = orig;
     Location offset;
     Shape = BlockShapeRegistry.BSD[0].GetShape(BlockDamage.NONE, out offset, false);
     SetPosition(pos.GetBlockLocation() + offset);
     SetOrientation(Quaternion.Identity);
 }
Beispiel #7
0
 protected override ItemStack GiveItemNoDup(ItemStack item)
 {
     // TODO: Better handling method here.
     ItemStack it = base.GiveItemNoDup(item);
     if (ReferenceEquals(it, item))
     {
         ((PlayerEntity)Owner).Network.SendPacket(new SpawnItemPacketOut(Items.Count - 1, it));
     }
     else
     {
         ((PlayerEntity)Owner).Network.SendPacket(new SetItemPacketOut(GetSlotForItem(it) - 1, it));
     }
     return it;
 }
Beispiel #8
0
 public static bool ItemsMatch(ItemStack item, ItemStack item2)
 {
     return item2.Datum == item.Datum &&
             item2.Name == item.Name &&
             item2.DisplayName == item.DisplayName &&
             item2.Description == item.Description &&
             item2.DrawColor == item.DrawColor &&
             item2.Image == item.Image &&
             item2.Volume == item.Volume &&
             item2.Weight == item.Weight &&
             item2.Model == item.Model &&
             ItemAttrsMatch(item2, item) &&
             ItemSharedAttrsMatch(item2, item) &&
             item2.IsBound == item.IsBound;
     // NOTE: Intentionally don't check the count or temperature here.
 }
Beispiel #9
0
 public static bool ItemAttrsMatch(ItemStack i1, ItemStack i2)
 {
     if (i1.Attributes.Count != i2.Attributes.Count)
     {
         return false;
     }
     foreach (string str in i1.Attributes.Keys)
     {
         if (!i2.Attributes.ContainsKey(str))
         {
             return false;
         }
         if (i1.Attributes[str].ToString() != i2.Attributes[str].ToString()) // TODO: Proper tag equality checks?
         {
             return false;
         }
     }
     return true;
 }
Beispiel #10
0
 public static bool ItemSharedAttrsMatch(ItemStack i1, ItemStack i2)
 {
     if (i1.SharedAttributes.Count != i2.SharedAttributes.Count)
     {
         return false;
     }
     foreach (string str in i1.SharedAttributes.Keys)
     {
         if (!i2.SharedAttributes.ContainsKey(str))
         {
             return false;
         }
         if (i1.SharedAttributes[str].ToString() != i2.SharedAttributes[str].ToString())
         {
             return false;
         }
     }
     return true;
 }
Beispiel #11
0
 public ItemRegistry(Server tserver)
 {
     TheServer = tserver;
     Air = new ItemStack("air", TheServer, 0, "clear", "Air", "Empty air", System.Drawing.Color.White, "none", true, 0);
     BaseItems.Add("air", Air);
 }
Beispiel #12
0
 protected override ItemStack GiveItemNoDup(ItemStack item)
 {
     ItemStack it = base.GiveItemNoDup(item);
     it.Info.PrepItem(Owner, it);
     return it;
 }
Beispiel #13
0
 public ItemTag(ItemStack itm)
 {
     Internal = itm;
 }
Beispiel #14
0
 public abstract void Use(Entity entity, ItemStack item);
Beispiel #15
0
 public abstract void SwitchTo(Entity entity, ItemStack item);
Beispiel #16
0
 // TODO: Entity -> LivingEntity? Or CharacterEntity?
 public abstract void PrepItem(Entity entity, ItemStack item);
Beispiel #17
0
 public static ItemStack FromString(Server tserver, string input)
 {
     int brack = input.IndexOf('[');
     string name = input.Substring(0, brack);
     string contents = input.Substring(brack + 1, input.Length - (brack + 1));
     List<KeyValuePair<string, string>> pairs = SplitUpPairs(contents);
     string secname = "";
     int count = 1;
     string tex = "";
     string display = "";
     string descrip = "";
     string model = "";
     string components = "";
     bool bound = false;
     string shared = "";
     string local = "";
     double weight = 1;
     double volume = 1;
     int datum = 0;
     double temperature = 0;
     System.Drawing.Color color = System.Drawing.Color.White;
     bool renderComp;
     Location renderCompOffs;
     foreach (KeyValuePair<string, string> pair in pairs)
     {
         string tkey = UnescapeTagBase.Unescape(pair.Key);
         string tval = UnescapeTagBase.Unescape(pair.Value);
         switch (tkey)
         {
             case "secondary":
                 secname = tval;
                 break;
             case "display":
                 display = tval;
                 break;
             case "count":
                 count = Utilities.StringToInt(tval);
                 break;
             case "description":
                 descrip = tval;
                 break;
             case "texture":
                 tex = tval;
                 break;
             case "model":
                 model = tval;
                 break;
             case "bound":
                 bound = tval == "true";
                 break;
             case "drawcolor":
                 color = (ColorTag.For(tval) ?? new ColorTag(color)).Internal;
                 break;
             case "datum":
                 datum = Utilities.StringToInt(tval);
                 break;
             case "weight":
                 weight = Utilities.StringToFloat(tval);
                 break;
             case "volume":
                 volume = Utilities.StringToFloat(tval);
                 break;
             case "temperature":
                 temperature = Utilities.StringToFloat(tval);
                 break;
             case "shared":
                 shared = tval;
                 break;
             case "local":
                 local = tval;
                 break;
             case "components":
                 components = tval;
                 break;
             case "renderascomponent":
                 renderComp = tval.ToLowerFast() == "true";
                 break;
             case "componentrenderoffset":
                 renderCompOffs = Location.FromString(tval);
                 break;
             default:
                 break; // Ignore errors as much as possible here.
                 // TODO: Maybe actually just error?
         }
     }
     ItemStack item = new ItemStack(name, secname, tserver, count, tex, display, descrip, color, model, bound, datum);
     item.Weight = weight;
     item.Volume = volume;
     item.Temperature = temperature;
     pairs = SplitUpPairs(shared.Substring(1, shared.Length - 2));
     foreach (KeyValuePair<string, string> pair in pairs)
     {
         string dat = UnescapeTagBase.Unescape(pair.Value);
         string type = dat.Substring(0, 4);
         string content = dat.Substring(5);
         TemplateObject togive = TOFor(tserver, type, content);
         item.SharedAttributes.Add(UnescapeTagBase.Unescape(pair.Key), togive);
     }
     pairs = SplitUpPairs(local.Substring(1, local.Length - 2));
     foreach (KeyValuePair<string, string> pair in pairs)
     {
         string dat = UnescapeTagBase.Unescape(pair.Value);
         string type = dat.Substring(0, 4);
         string content = dat.Substring(5);
         TemplateObject togive = TOFor(tserver, type, content);
         item.Attributes.Add(UnescapeTagBase.Unescape(pair.Key), togive);
     }
     string[] npairs = components.Substring(1, local.Length - 2).SplitFast(';', 2);
     foreach (string pair in npairs)
     {
         string dat = UnescapeTagBase.Unescape(pair);
         if (dat.Length > 0)
         {
             item.Components.Add(FromString(tserver, dat));
         }
     }
     return item;
 }
Beispiel #18
0
        private ItemStack Load(string name)
        {
            string tname = name.ToLowerFast();
            string fname = "items/" + tname + ".itm";

            if (!TheServer.Files.Exists(fname))
            {
                SysConsole.Output(OutputType.WARNING, "Tried to load non-existent item: " + name);
                return(null);
            }
            try
            {
                string   fdata           = TheServer.Files.ReadText(fname);
                string[] split           = fdata.Replace('\r', '\n').SplitFast('\n');
                string   res_type        = "";
                string   res_icon        = "";
                string   res_display     = "";
                string   res_description = "";
                string   res_color       = "";
                string   res_model       = "";
                string   res_bound       = "";
                string   res_subtype     = null;
                string   res_datum       = "0";
                string   res_weight      = "1";
                string   res_volume      = "1";
                List <KeyValuePair <string, string> > attrs  = new List <KeyValuePair <string, string> >();
                List <KeyValuePair <string, string> > shared = new List <KeyValuePair <string, string> >();
                foreach (string line in split)
                {
                    if (line.Trim().Length < 3)
                    {
                        continue;
                    }
                    string[] dat      = line.SplitFast(':', 1);
                    string   dat_type = dat[0].Trim().ToLowerFast();
                    string   dat_val  = dat[1].Trim();
                    switch (dat_type)
                    {
                    case "type":
                        res_type = dat_val;
                        break;

                    case "subtype":
                        res_subtype = dat_val;
                        break;

                    case "icon":
                        res_icon = dat_val;
                        break;

                    case "display":
                        res_display = dat_val;
                        break;

                    case "description":
                        res_description = dat_val;
                        break;

                    case "color":
                        res_color = dat_val;
                        break;

                    case "model":
                        res_model = dat_val;
                        break;

                    case "bound":
                        res_bound = dat_val;
                        break;

                    case "datum":
                        res_datum = dat_val;
                        break;

                    case "weight":
                        res_weight = dat_val;
                        break;

                    case "volume":
                        res_volume = dat_val;
                        break;

                    default:
                        if (dat_type.StartsWith("shared."))
                        {
                            string opt = dat_type.Substring("shared.".Length).ToLower();
                            shared.Add(new KeyValuePair <string, string>(opt, dat_val));
                        }
                        else if (dat_type.StartsWith("attributes."))
                        {
                            string opt = dat_type.Substring("attributes.".Length).ToLower();
                            attrs.Add(new KeyValuePair <string, string>(opt, dat_val));
                        }
                        break;
                    }
                }
                if (string.IsNullOrEmpty(res_display))
                {
                    res_display = "^[lang=voxalia|items." + tname.Replace("/", ".") + ".display]";
                }
                if (string.IsNullOrEmpty(res_description))
                {
                    res_description = "^[lang=voxalia|items." + tname.Replace("/", ".") + ".description]";
                }
                ItemStack it = new ItemStack(res_type, res_subtype, TheServer, 1, res_icon, res_display, res_description, ColorTag.For(res_color).Internal, res_model,
                                             res_bound.ToLower() == "true", Utilities.StringToInt(res_datum))
                {
                    Weight = Utilities.StringToFloat(res_weight),
                    Volume = Utilities.StringToFloat(res_volume)
                };
                foreach (KeyValuePair <string, string> key in shared)
                {
                    string         dat     = UnescapeTagBase.Unescape(key.Value);
                    string         type    = dat.Substring(0, 4);
                    string         content = dat.Substring(5);
                    TemplateObject togive  = ItemStack.TOFor(TheServer, type, content);
                    it.SharedAttributes[key.Key] = togive;
                }
                foreach (KeyValuePair <string, string> key in attrs)
                {
                    string         dat     = UnescapeTagBase.Unescape(key.Value);
                    string         type    = dat.Substring(0, 4);
                    string         content = dat.Substring(5);
                    TemplateObject togive  = ItemStack.TOFor(TheServer, type, content);
                    it.Attributes[key.Key] = togive;
                }
                return(it);
            }
            catch (Exception ex)
            {
                Utilities.CheckException(ex);
                SysConsole.Output("Loading item '" + name + "'", ex);
                return(null);
            }
        }
Beispiel #19
0
 public ItemRegistry(Server tserver)
 {
     TheServer = tserver;
     Air       = new ItemStack("air", TheServer, 0, "clear", "Air", "Empty air", System.Drawing.Color.White, "none", true, 0);
     BaseItems.Add("air", Air);
 }
Beispiel #20
0
 public override void SetSlot(int slot, ItemStack item)
 {
     base.SetSlot(slot, item);
     ((PlayerEntity)Owner).Network.SendPacket(new SetItemPacketOut(slot, item));
 }
Beispiel #21
0
 private ItemStack Load(string name)
 {
     string tname = name.ToLowerFast();
     string fname = "items/" + tname + ".itm";
     if (!TheServer.Files.Exists(fname))
     {
         SysConsole.Output(OutputType.WARNING, "Tried to load non-existent item: " + name);
         return null;
     }
     try
     {
         string fdata = TheServer.Files.ReadText(fname);
         string[] split = fdata.Replace('\r', '\n').SplitFast('\n');
         string res_type = "";
         string res_icon = "";
         string res_display = "";
         string res_description = "";
         string res_color = "";
         string res_model = "";
         string res_bound = "";
         string res_subtype = null;
         string res_datum = "0";
         string res_weight = "1";
         string res_volume = "1";
         List<KeyValuePair<string, string>> attrs = new List<KeyValuePair<string, string>>();
         List<KeyValuePair<string, string>> shared = new List<KeyValuePair<string, string>>();
         foreach (string line in split)
         {
             if (line.Trim().Length < 3)
             {
                 continue;
             }
             string[] dat = line.SplitFast(':', 1);
             string dat_type = dat[0].Trim().ToLowerFast();
             string dat_val = dat[1].Trim();
             switch (dat_type)
             {
                 case "type":
                     res_type = dat_val;
                     break;
                 case "subtype":
                     res_subtype = dat_val;
                     break;
                 case "icon":
                     res_icon = dat_val;
                     break;
                 case "display":
                     res_display = dat_val;
                     break;
                 case "description":
                     res_description = dat_val;
                     break;
                 case "color":
                     res_color = dat_val;
                     break;
                 case "model":
                     res_model = dat_val;
                     break;
                 case "bound":
                     res_bound = dat_val;
                     break;
                 case "datum":
                     res_datum = dat_val;
                     break;
                 case "weight":
                     res_weight = dat_val;
                     break;
                 case "volume":
                     res_volume = dat_val;
                     break;
                 default:
                     if (dat_type.StartsWith("shared."))
                     {
                         string opt = dat_type.Substring("shared.".Length).ToLower();
                         shared.Add(new KeyValuePair<string, string>(opt, dat_val));
                     }
                     else if (dat_type.StartsWith("attributes."))
                     {
                         string opt = dat_type.Substring("attributes.".Length).ToLower();
                         attrs.Add(new KeyValuePair<string, string>(opt, dat_val));
                     }
                     break;
             }
         }
         if (string.IsNullOrEmpty(res_display))
         {
             res_display = "^[lang=voxalia|items." + tname.Replace("/", ".") + ".display]";
         }
         if (string.IsNullOrEmpty(res_description))
         {
             res_description = "^[lang=voxalia|items." + tname.Replace("/", ".") + ".description]";
         }
         ItemStack it = new ItemStack(res_type, res_subtype, TheServer, 1, res_icon, res_display, res_description, ColorTag.For(res_color).Internal, res_model,
             res_bound.ToLower() == "true", Utilities.StringToInt(res_datum))
         {
             Weight = Utilities.StringToFloat(res_weight),
             Volume = Utilities.StringToFloat(res_volume)
         };
         foreach (KeyValuePair<string, string> key in shared)
         {
             string dat = UnescapeTagBase.Unescape(key.Value);
             string type = dat.Substring(0, 4);
             string content = dat.Substring(5);
             TemplateObject togive = ItemStack.TOFor(TheServer, type, content);
             it.SharedAttributes[key.Key] = togive;
         }
         foreach (KeyValuePair<string, string> key in attrs)
         {
             string dat = UnescapeTagBase.Unescape(key.Value);
             string type = dat.Substring(0, 4);
             string content = dat.Substring(5);
             TemplateObject togive = ItemStack.TOFor(TheServer, type, content);
             it.Attributes[key.Key] = togive;
         }
         return it;
     }
     catch (Exception ex)
     {
         Utilities.CheckException(ex);
         SysConsole.Output("Loading item '" + name + "'", ex);
         return null;
     }
 }
Beispiel #22
0
 public int GetSlotForItem(ItemStack item)
 {
     for (int i = 0; i < Items.Count; i++)
     {
         if (Items[i] == item)
         {
             return i + 1;
         }
     }
     return -1;
 }
Beispiel #23
0
 public virtual void SetSlot(int slot, ItemStack item)
 {
     Items[slot] = item;
 }
Beispiel #24
0
 public bool RemoveItem(ItemStack item, int count)
 {
     for (int i = 0; i < Items.Count; i++)
     {
         if (ItemsMatch(item, Items[i]))
         {
             if (item.Count > count)
             {
                 item.Count -= count;
                 SetSlot(i, item);
                 return true;
             }
             else
             {
                 count -= item.Count;
                 RemoveItem(i + 1);
                 if (count == 0)
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Beispiel #25
0
 public abstract void ReleaseClick(Entity entity, ItemStack item);
Beispiel #26
0
 public List<RecipeResult> CanCraftFrom(params ItemStack[] input)
 {
     ItemStack[] inpitems = new ItemStack[input.Length];
     input.CopyTo(inpitems, 0);
     List<RecipeResult> items = new List<RecipeResult>();
     for (int i = 0; i < Recipes.Count; i++)
     {
         if (Recipes[i].Input.Length > input.Length)
         {
             continue;
         }
         List<ItemStack> usedhere = new List<ItemStack>();
         for (int x = 0; x < Recipes[i].Input.Length; x++)
         {
             int used;
             if (!HasRequirement(Recipes[i].Mode, Recipes[i].Input[x], inpitems, out used))
             {
                 goto rip;
             }
             inpitems[used] = null;
             ItemStack usednow = input[i].Duplicate();
             usednow.Count = Recipes[i].Input[x].Count;
             usedhere.Add(usednow);
         }
         items.Add(new RecipeResult() { Recipe = Recipes[i], UsedInput = usedhere });
         rip:
         continue;
     }
     return items;
 }
Beispiel #27
0
 public abstract void Tick(Entity entity, ItemStack item);
Beispiel #28
0
 public string AnimToHold(ItemStack item)
 {
     if (item.Name == "rifle_gun")
     {
         return "torso_armed_rifle";
     }
     return "torso_armed_rifle";
     //return "idle01";
 }
Beispiel #29
0
 public void GiveItem(ItemStack item)
 {
     if (item.Name == "air")
     {
         return;
     }
     GiveItemNoDup(item.Duplicate());
 }
Beispiel #30
0
 protected virtual ItemStack GiveItemNoDup(ItemStack item)
 {
     for (int i = 0; i < Items.Count; i++)
     {
         if (ItemsMatch(item, Items[i]))
         {
             Items[i].Temperature = (item.Temperature * item.Count) + (Items[i].Temperature * item.Count) / (item.Count + Items[i].Count);
             Items[i].Count += item.Count;
             return Items[i];
         }
     }
     Items.Add(item);
     return item;
 }
Beispiel #31
0
 public PhysicsEntity ItemToEntity(ItemStack item)
 {
     if (item.Info is BlockItem)
     {
         return new BlockItemEntity(this, BlockInternal.FromItemDatum(item.Datum), Location.Zero);
     }
     if (item.Info is GlowstickItem)
     {
         return new GlowstickEntity(item.DrawColor, this);
     }
     if (item.Info is SmokegrenadeItem)
     {
         return new SmokeGrenadeEntity(item.DrawColor, this, item.GetAttributeI("big_smoke", 0) == 0 ? ParticleEffectNetType.SMOKE : ParticleEffectNetType.BIG_SMOKE)
         {
             SmokeLeft = item.GetAttributeI("max_smoke", 300)
         };
     }
     if (item.Info is ExplosivegrenadeItem)
     {
         return new ExplosiveGrenadeEntity(this);
     }
     if (item.Info is PaintbombItem)
     {
         int paint = item.Datum;
         return new PaintBombEntity((byte)paint, this);
     }
     return new ItemEntity(item, this);
 }
Beispiel #32
0
 public bool HasRequirement(RecipeMode mode, ItemStack requirement, ItemStack[] input, out int used)
 {
     for (int i = 0; i < input.Length; i++)
     {
         if (input[i] == null)
         {
             continue;
         }
         bool thisone = true;
         if (input[i].Count < requirement.Count)
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.TYPE) && requirement.Name != input[i].Name)
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.SECONDARY) && requirement.SecondaryName != input[i].SecondaryName)
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.TEXTURE) && requirement.GetTextureName() != input[i].GetTextureName())
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.MODEL) && requirement.GetModelName() != input[i].GetModelName())
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.MODEL) && requirement.GetModelName() != input[i].GetModelName())
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.SHARED) && !Inventory.ItemSharedAttrsMatch(requirement, input[i]))
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.LOCAL) && !Inventory.ItemAttrsMatch(requirement, input[i]))
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.DISPLAY) && requirement.DisplayName != input[i].DisplayName)
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.DESCRIPTION) && requirement.Description != input[i].Description)
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.COLOR) && requirement.DrawColor.A != input[i].DrawColor.A && requirement.DrawColor.R != input[i].DrawColor.R
              && requirement.DrawColor.G != input[i].DrawColor.G && requirement.DrawColor.B != input[i].DrawColor.B)
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.DATUM) && requirement.Datum != input[i].Datum)
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.BOUND) && requirement.IsBound != input[i].IsBound)
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.WEIGHT) && requirement.Weight != input[i].Weight)
         {
             thisone = false;
         }
         else if (mode.HasFlag(RecipeMode.VOLUME) && requirement.Volume != input[i].Volume)
         {
             thisone = false;
         }
         else if (thisone)
         {
             used = i;
             return true;
         }
     }
     used = -1;
     return false;
 }