Exemplo n.º 1
0
        internal override void ConfigureFromJson(JToken compData)
        {
            enterMessage = $"{parent.name} enters from the $DIR.";
            leaveMessage = $"{parent.name} leaves to the $DIR.";
            deathMessage = $"The corpse of {parent.name} lies here.";

            Bodyplan bp = null;

            if (!JsonExtensions.IsNullOrEmpty(compData["mobtype"]))
            {
                bp = Modules.Bodies.GetPlan((string)compData["mobtype"]);
            }
            if (bp == null)
            {
                bp = Modules.Bodies.GetPlan("humanoid");
            }

            foreach (Bodypart b in bp.allParts)
            {
                GameObject newLimb = (GameObject)Game.Objects.CreateNewInstance(false);
                newLimb.name = "limb";
                newLimb.aliases.Add("bodypart");

                VisibleComponent vis = (VisibleComponent)newLimb.AddComponent(Text.CompVisible);
                vis.SetValue(Text.FieldShortDesc, b.name);
                vis.SetValue(Text.FieldRoomDesc, $"A severed {b.name} has been left here.");
                vis.SetValue(Text.FieldExaminedDesc, $"It is a severed {b.name} that has been lopped off its owner.");

                PhysicsComponent phys = (PhysicsComponent)newLimb.AddComponent(Text.CompPhysics);
                phys.width      = b.width;
                phys.length     = b.length;
                phys.height     = b.height;
                phys.strikeArea = b.strikeArea;
                phys.edged      = b.isEdged;
                phys.UpdateValues();

                BodypartComponent body = (BodypartComponent)newLimb.AddComponent(Text.CompBodypart);
                body.canGrasp        = b.canGrasp;
                body.canStand        = b.canStand;
                body.isNaturalWeapon = b.isNaturalWeapon;

                foreach (string s in b.equipmentSlots)
                {
                    if (!body.equipmentSlots.Contains(s))
                    {
                        body.equipmentSlots.Add(s);
                    }
                }
                Game.Objects.AddDatabaseEntry(newLimb);
                limbs.Add(b.name, newLimb);
            }
            UpdateLists();
        }
Exemplo n.º 2
0
        internal override void Initialize()
        {
            Modules.Bodies = this;
            Debug.WriteLine("- Loading bodypart definitions.");
            foreach (var f in (from file in Directory.EnumerateFiles(@"data/definitions/bodies/parts", "*.json", SearchOption.AllDirectories) select new { File = file }))
            {
                Debug.WriteLine($"- Loading bodypart definition {f.File}.");
                try
                {
                    JObject  r  = JObject.Parse(File.ReadAllText(f.File));
                    Bodypart bp = new Bodypart(
                        (string)r["name"],
                        (string)r["root"],
                        JsonConvert.DeserializeObject <List <string> >(r["slots"].ToString())
                        );
                    if (!JsonExtensions.IsNullOrEmpty(r["grasp"]))
                    {
                        bp.canGrasp = (bool)r["grasp"];
                    }
                    if (!JsonExtensions.IsNullOrEmpty(r["stance"]))
                    {
                        bp.canStand = (bool)r["stance"];
                    }
                    if (!JsonExtensions.IsNullOrEmpty(r["vital"]))
                    {
                        bp.isVital = (bool)r["vital"];
                    }
                    if (!JsonExtensions.IsNullOrEmpty(r["attackstrings"]))
                    {
                        bp.isNaturalWeapon = true;
                        //bp.attackStrings = JsonConvert.DeserializeObject<List<Tuple<string, string>>>(r["attackstrings"].ToString());
                    }
                    if (!JsonExtensions.IsNullOrEmpty(r["physics"]))
                    {
                        bp.contactData = JsonConvert.DeserializeObject <Dictionary <string, int> >(r["physics"].ToString());
                    }
                    parts.Add(bp.name, bp);
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Exception when loading bodypart from file {f.File} - {e.Message}");
                }
            }
            Debug.WriteLine("Done.\nLoading bodyplan definitions.");
            foreach (var f in (from file in Directory.EnumerateFiles(@"data/definitions/bodies/plans", "*.json", SearchOption.AllDirectories) select new { File = file }))
            {
                Debug.WriteLine($"- Loading bodyplan definition {f.File}.");
                try
                {
                    JObject  r     = JObject.Parse(File.ReadAllText(f.File));
                    Bodyplan bPlan = new Bodyplan(r["name"].ToString().ToLower());
                    foreach (JProperty token in r["parts"].Children <JProperty>())
                    {
                        Bodypart child = GetPart(token.Name.ToString());
                        bPlan.allParts.Add(child);
                        Bodypart parent = token.Value != null?GetPart(token.Value.ToString()) : null;

                        if (parent != null)
                        {
                            bPlan.childToParent.Add(child, parent);
                            if (!bPlan.parentToChildren.ContainsKey(parent))
                            {
                                bPlan.parentToChildren.Add(parent, new List <Bodypart>());
                            }
                            bPlan.parentToChildren[parent].Add(child);
                        }
                    }
                    plans.Add(bPlan.name, bPlan);
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Exception when loading bodyplan from file {f.File} - {e.Message}");
                }
            }
            Debug.WriteLine("Done.");
        }