public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     ComponentBody           = base.Entity.FindComponent <ComponentBody>(throwOnError: true);
     ComponentHealth         = base.Entity.FindComponent <ComponentHealth>(throwOnError: true);
     ComponentSpawn          = base.Entity.FindComponent <ComponentSpawn>(throwOnError: true);
     ComponentCreatureSounds = base.Entity.FindComponent <ComponentCreatureSounds>(throwOnError: true);
     ComponentCreatureModel  = base.Entity.FindComponent <ComponentCreatureModel>(throwOnError: true);
     ComponentLocomotion     = base.Entity.FindComponent <ComponentLocomotion>(throwOnError: true);
     m_subsystemPlayerStats  = base.Project.FindSubsystem <SubsystemPlayerStats>(throwOnError: true);
     ConstantSpawn           = valuesDictionary.GetValue <bool>("ConstantSpawn");
     Category    = valuesDictionary.GetValue <CreatureCategory>("Category");
     DisplayName = valuesDictionary.GetValue <string>("DisplayName");
     if (DisplayName.StartsWith("[") && DisplayName.EndsWith("]"))
     {
         string[] lp = DisplayName.Substring(1, DisplayName.Length - 2).Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
         DisplayName = LanguageControl.GetDatabase("DisplayName", lp[1]);
     }
     m_killVerbs = HumanReadableConverter.ValuesListFromString <string>(',', valuesDictionary.GetValue <string>("KillVerbs"));
     if (m_killVerbs.Length == 0)
     {
         throw new InvalidOperationException("Must have at least one KillVerb");
     }
     if (!MathUtils.IsPowerOf2((long)Category))
     {
         throw new InvalidOperationException("A single category must be assigned for creature.");
     }
 }
        public BestiaryScreen()
        {
            XElement node = ContentManager.Get <XElement>("Screens/BestiaryScreen");

            LoadContents(this, node);
            m_creaturesList = Children.Find <ListPanelWidget>("CreaturesList");
            m_creaturesList.ItemWidgetFactory = delegate(object item)
            {
                BestiaryCreatureInfo bestiaryCreatureInfo2 = (BestiaryCreatureInfo)item;
                XElement             node2       = ContentManager.Get <XElement>("Widgets/BestiaryItem");
                ContainerWidget      obj         = (ContainerWidget)Widget.LoadWidget(this, node2, null);
                ModelWidget          modelWidget = obj.Children.Find <ModelWidget>("BestiaryItem.Model");
                SetupBestiaryModelWidget(bestiaryCreatureInfo2, modelWidget, (m_creaturesList.Items.IndexOf(item) % 2 == 0) ? new Vector3(-1f, 0f, -1f) : new Vector3(1f, 0f, -1f), autoRotate: false, autoAspect: false);
                obj.Children.Find <LabelWidget>("BestiaryItem.Text").Text    = bestiaryCreatureInfo2.DisplayName;
                obj.Children.Find <LabelWidget>("BestiaryItem.Details").Text = bestiaryCreatureInfo2.Description;
                return(obj);
            };
            m_creaturesList.ItemClicked += delegate(object item)
            {
                ScreensManager.SwitchScreen("BestiaryDescription", item, m_creaturesList.Items.Cast <BestiaryCreatureInfo>().ToList());
            };
            List <BestiaryCreatureInfo> list = new List <BestiaryCreatureInfo>();

            foreach (ValuesDictionary entitiesValuesDictionary in DatabaseManager.EntitiesValuesDictionaries)
            {
                ValuesDictionary valuesDictionary = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentCreature));
                if (valuesDictionary != null)
                {
                    string value = valuesDictionary.GetValue <string>("DisplayName");
                    if (value.StartsWith("[") && value.EndsWith("]"))
                    {
                        string[] lp = value.Substring(1, value.Length - 2).Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                        value = LanguageControl.GetDatabase("DisplayName", lp[1]);
                    }
                    if (!string.IsNullOrEmpty(value))
                    {
                        int order = -1;
                        ValuesDictionary value2 = entitiesValuesDictionary.GetValue <ValuesDictionary>("CreatureEggData", null);
                        ValuesDictionary value3 = entitiesValuesDictionary.GetValue <ValuesDictionary>("Player", null);
                        if (value2 != null || value3 != null)
                        {
                            if (value2 != null)
                            {
                                int value4 = value2.GetValue <int>("EggTypeIndex");
                                if (value4 < 0)
                                {
                                    continue;
                                }
                                order = value4;
                            }
                            ValuesDictionary valuesDictionary2 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentCreatureModel));
                            ValuesDictionary valuesDictionary3 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentBody));
                            ValuesDictionary valuesDictionary4 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentHealth));
                            ValuesDictionary valuesDictionary5 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentMiner));
                            ValuesDictionary valuesDictionary6 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentLocomotion));
                            ValuesDictionary valuesDictionary7 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentHerdBehavior));
                            ValuesDictionary valuesDictionary8 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentMount));
                            ValuesDictionary valuesDictionary9 = DatabaseManager.FindValuesDictionaryForComponent(entitiesValuesDictionary, typeof(ComponentLoot));
                            string           dy = valuesDictionary.GetValue <string>("Description");
                            if (dy.StartsWith("[") && dy.EndsWith("]"))
                            {
                                string[] lp = dy.Substring(1, dy.Length - 2).Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                                dy = LanguageControl.GetDatabase("Description", lp[1]);
                            }
                            BestiaryCreatureInfo bestiaryCreatureInfo = new BestiaryCreatureInfo
                            {
                                Order            = order,
                                DisplayName      = value,
                                Description      = dy,
                                ModelName        = valuesDictionary2.GetValue <string>("ModelName"),
                                TextureOverride  = valuesDictionary2.GetValue <string>("TextureOverride"),
                                Mass             = valuesDictionary3.GetValue <float>("Mass"),
                                AttackResilience = valuesDictionary4.GetValue <float>("AttackResilience"),
                                AttackPower      = (valuesDictionary5?.GetValue <float>("AttackPower") ?? 0f),
                                MovementSpeed    = MathUtils.Max(valuesDictionary6.GetValue <float>("WalkSpeed"), valuesDictionary6.GetValue <float>("FlySpeed"), valuesDictionary6.GetValue <float>("SwimSpeed")),
                                JumpHeight       = MathUtils.Sqr(valuesDictionary6.GetValue <float>("JumpSpeed")) / 20f,
                                IsHerding        = (valuesDictionary7 != null),
                                CanBeRidden      = (valuesDictionary8 != null),
                                HasSpawnerEgg    = (value2?.GetValue <bool>("ShowEgg") ?? false),
                                Loot             = ((valuesDictionary9 != null) ? ComponentLoot.ParseLootList(valuesDictionary9.GetValue <ValuesDictionary>("Loot")) : new List <ComponentLoot.Loot>())
                            };
                            if (value3 != null && entitiesValuesDictionary.DatabaseObject.Name.ToLower().Contains("female"))
                            {
                                bestiaryCreatureInfo.AttackPower      *= 0.8f;
                                bestiaryCreatureInfo.AttackResilience *= 0.8f;
                                bestiaryCreatureInfo.MovementSpeed    *= 1.03f;
                                bestiaryCreatureInfo.JumpHeight       *= MathUtils.Sqr(1.03f);
                            }
                            list.Add(bestiaryCreatureInfo);
                        }
                    }
                }
            }
            foreach (BestiaryCreatureInfo item in list.OrderBy((BestiaryCreatureInfo ci) => ci.Order))
            {
                m_creaturesList.AddItem(item);
            }
        }
        public override void Update()
        {
            m_characterSkinsCache.GetTexture(m_playerData.CharacterSkinName);
            m_playerModel.PlayerClass       = m_playerData.PlayerClass;
            m_playerModel.CharacterSkinName = m_playerData.CharacterSkinName;
            m_playerClassButton.Text        = m_playerData.PlayerClass.ToString();
            if (!m_nameTextBox.HasFocus)
            {
                m_nameTextBox.Text = m_playerData.Name;
            }
            m_characterSkinLabel.Text = CharacterSkinsManager.GetDisplayName(m_playerData.CharacterSkinName);
            m_controlsLabel.Text      = GetDeviceDisplayName(m_inputDevices.Where((WidgetInputDevice id) => (id & m_playerData.InputDevice) != 0).FirstOrDefault());
            ValuesDictionary valuesDictionary = DatabaseManager.FindValuesDictionaryForComponent(DatabaseManager.FindEntityValuesDictionary(m_playerData.GetEntityTemplateName(), throwIfNotFound: true), typeof(ComponentCreature));
            string           dy = valuesDictionary.GetValue <string>("Description");

            if (dy.StartsWith("[") && dy.EndsWith("]"))
            {
                string[] lp = dy.Substring(1, dy.Length - 2).Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                dy = LanguageControl.GetDatabase("Description", lp[1]);
            }
            m_descriptionLabel.Text = dy;
            if (m_playerClassButton.IsClicked)
            {
                m_playerData.PlayerClass = ((m_playerData.PlayerClass == PlayerClass.Male) ? PlayerClass.Female : PlayerClass.Male);
                m_playerData.RandomizeCharacterSkin();
                if (m_playerData.IsDefaultName)
                {
                    m_playerData.ResetName();
                }
            }
            if (m_characterSkinButton.IsClicked)
            {
                CharacterSkinsManager.UpdateCharacterSkinsList();
                IEnumerable <string> items  = CharacterSkinsManager.CharacterSkinsNames.Where((string n) => CharacterSkinsManager.GetPlayerClass(n) == m_playerData.PlayerClass || !CharacterSkinsManager.GetPlayerClass(n).HasValue);
                ListSelectionDialog  dialog = new ListSelectionDialog(LanguageControl.Get(fName, 1), items, 64f, delegate(object item)
                {
                    XElement node       = ContentManager.Get <XElement>("Widgets/CharacterSkinItem");
                    ContainerWidget obj = (ContainerWidget)Widget.LoadWidget(this, node, null);
                    Texture2D texture   = m_characterSkinsCache.GetTexture((string)item);
                    obj.Children.Find <LabelWidget>("CharacterSkinItem.Text").Text    = CharacterSkinsManager.GetDisplayName((string)item);
                    obj.Children.Find <LabelWidget>("CharacterSkinItem.Details").Text = $"{texture.Width}x{texture.Height}";
                    PlayerModelWidget playerModelWidget    = obj.Children.Find <PlayerModelWidget>("CharacterSkinItem.Model");
                    playerModelWidget.PlayerClass          = m_playerData.PlayerClass;
                    playerModelWidget.CharacterSkinTexture = texture;
                    return(obj);
                }, delegate(object item)
                {
                    m_playerData.CharacterSkinName = (string)item;
                    if (m_playerData.IsDefaultName)
                    {
                        m_playerData.ResetName();
                    }
                });
                DialogsManager.ShowDialog(null, dialog);
            }
            if (m_controlsButton.IsClicked)
            {
                DialogsManager.ShowDialog(null, new ListSelectionDialog(LanguageControl.Get(fName, 2), m_inputDevices, 56f, (object d) => GetDeviceDisplayName((WidgetInputDevice)d), delegate(object d)
                {
                    WidgetInputDevice widgetInputDevice = (WidgetInputDevice)d;
                    m_playerData.InputDevice            = widgetInputDevice;
                    foreach (PlayerData playersDatum in m_playerData.SubsystemPlayers.PlayersData)
                    {
                        if (playersDatum != m_playerData && (playersDatum.InputDevice & widgetInputDevice) != 0)
                        {
                            playersDatum.InputDevice &= ~widgetInputDevice;
                        }
                    }
                }));
            }
            if (m_addButton.IsClicked && VerifyName())
            {
                m_playerData.SubsystemPlayers.AddPlayerData(m_playerData);
                ScreensManager.SwitchScreen("Players", m_playerData.SubsystemPlayers);
            }
            if (m_deleteButton.IsClicked)
            {
                DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "warning"), LanguageControl.Get(fName, 3), LanguageControl.Get("Usual", "ok"), LanguageControl.Get("Usual", "cancel"), delegate(MessageDialogButton b)
                {
                    if (b == MessageDialogButton.Button1)
                    {
                        m_playerData.SubsystemPlayers.RemovePlayerData(m_playerData);
                        ScreensManager.SwitchScreen("Players", m_playerData.SubsystemPlayers);
                    }
                }));
            }
            if (m_playButton.IsClicked && VerifyName())
            {
                m_playerData.SubsystemPlayers.AddPlayerData(m_playerData);
                ScreensManager.SwitchScreen("Game");
            }
            if (m_addAnotherButton.IsClicked && VerifyName())
            {
                m_playerData.SubsystemPlayers.AddPlayerData(m_playerData);
                ScreensManager.SwitchScreen("Player", Mode.Initial, m_playerData.SubsystemPlayers.Project);
            }
            if ((base.Input.Back || base.Input.Cancel || Children.Find <ButtonWidget>("TopBar.Back").IsClicked) && VerifyName())
            {
                if (m_mode == Mode.Initial)
                {
                    GameManager.SaveProject(waitForCompletion: true, showErrorDialog: true);
                    GameManager.DisposeProject();
                    ScreensManager.SwitchScreen("MainMenu");
                }
                else if (m_mode == Mode.Add || m_mode == Mode.Edit)
                {
                    ScreensManager.SwitchScreen("Players", m_playerData.SubsystemPlayers);
                }
            }
            m_nameWasInvalid = false;
        }
Exemple #4
0
        public override void Initialize()
        {
            Dictionary <int, EggType> dictionary       = new Dictionary <int, EggType>();
            DatabaseObjectType        parameterSetType = DatabaseManager.GameDatabase.ParameterSetType;
            Guid eggParameterSetGuid = new Guid("300ff557-775f-4c7c-a88a-26655369f00b");

            foreach (DatabaseObject item in from o in DatabaseManager.GameDatabase.Database.Root.GetExplicitNestingChildren(parameterSetType, directChildrenOnly: false)
                     where o.EffectiveInheritanceRoot.Guid == eggParameterSetGuid
                     select o)
            {
                int nestedValue = item.GetNestedValue <int>("EggTypeIndex");
                if (nestedValue >= 0)
                {
                    if (dictionary.ContainsKey(nestedValue))
                    {
                        throw new InvalidOperationException($"Duplicate creature egg data EggTypeIndex ({nestedValue}).");
                    }
                    string value = item.GetNestedValue <string>("DisplayName");
                    if (value.StartsWith("[") && value.EndsWith("]"))
                    {
                        string[] lp = value.Substring(1, value.Length - 2).Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                        value = LanguageControl.GetDatabase("DisplayName", lp[1]);
                    }
                    dictionary.Add(nestedValue, new EggType
                    {
                        EggTypeIndex     = nestedValue,
                        ShowEgg          = item.GetNestedValue <bool>("ShowEgg"),
                        DisplayName      = value,
                        TemplateName     = item.NestingParent.Name,
                        NutritionalValue = item.GetNestedValue <float>("NutritionalValue"),
                        Color            = item.GetNestedValue <Color>("Color"),
                        ScaleUV          = item.GetNestedValue <Vector2>("ScaleUV"),
                        SwapUV           = item.GetNestedValue <bool>("SwapUV"),
                        Scale            = item.GetNestedValue <float>("Scale"),
                        TextureSlot      = item.GetNestedValue <int>("TextureSlot")
                    });
                }
            }
            for (int i = 0; i < dictionary.Count; i++)
            {
                if (dictionary.TryGetValue(i, out EggType value))
                {
                    m_eggTypes.Add(value);
                    continue;
                }
                throw new InvalidOperationException($"Missing creature egg data EggTypeIndex value {i}.");
            }
            Model  model = ContentManager.Get <Model>("Models/Egg");
            Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Egg").ParentBone);

            foreach (EggType eggType in m_eggTypes)
            {
                eggType.BlockMesh = new BlockMesh();
                eggType.BlockMesh.AppendModelMeshPart(model.FindMesh("Egg").MeshParts[0], boneAbsoluteTransform, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, eggType.Color);
                Matrix identity = Matrix.Identity;
                if (eggType.SwapUV)
                {
                    identity.M11 = 0f;
                    identity.M12 = 1f;
                    identity.M21 = 1f;
                    identity.M22 = 0f;
                }
                identity *= Matrix.CreateScale(0.0625f * eggType.ScaleUV.X, 0.0625f * eggType.ScaleUV.Y, 1f);
                identity *= Matrix.CreateTranslation((float)(eggType.TextureSlot % 16) / 16f, (float)(eggType.TextureSlot / 16) / 16f, 0f);
                eggType.BlockMesh.TransformTextureCoordinates(identity);
            }
            base.Initialize();
        }