Пример #1
0
        public void DropAllItems(Vector3 position)
        {
            Random             random             = new Random();
            SubsystemPickables subsystemPickables = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);

            for (int i = 0; i < SlotsCount; i++)
            {
                int slotCount = GetSlotCount(i);
                if (slotCount > 0)
                {
                    int     slotValue = GetSlotValue(i);
                    int     count     = RemoveSlotItems(i, slotCount);
                    Vector3 value     = random.Float(5f, 10f) * Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(1f, 2f), random.Float(-1f, 1f)));
                    subsystemPickables.AddPickable(slotValue, count, position, value, null);
                }
            }
        }
Пример #2
0
        public void DragDrop(Widget dragWidget, object data)
        {
            InventoryDragData inventoryDragData = data as InventoryDragData;

            if (inventoryDragData != null && GameManager.Project != null)
            {
                SubsystemPickables subsystemPickables = GameManager.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);
                ComponentPlayer    componentPlayer    = GameWidget.PlayerData.ComponentPlayer;
                int slotValue = inventoryDragData.Inventory.GetSlotValue(inventoryDragData.SlotIndex);
                int count     = (componentPlayer != null && componentPlayer.ComponentInput.SplitSourceInventory == inventoryDragData.Inventory && componentPlayer.ComponentInput.SplitSourceSlotIndex == inventoryDragData.SlotIndex) ? 1 : ((inventoryDragData.DragMode != DragMode.SingleItem) ? inventoryDragData.Inventory.GetSlotCount(inventoryDragData.SlotIndex) : MathUtils.Min(inventoryDragData.Inventory.GetSlotCount(inventoryDragData.SlotIndex), 1));
                int num       = inventoryDragData.Inventory.RemoveSlotItems(inventoryDragData.SlotIndex, count);
                if (num > 0)
                {
                    Vector2 vector = dragWidget.WidgetToScreen(dragWidget.ActualSize / 2f);
                    Vector3 value  = Vector3.Normalize(GameWidget.ActiveCamera.ScreenToWorld(new Vector3(vector.X, vector.Y, 1f), Matrix.Identity) - GameWidget.ActiveCamera.ViewPosition) * 12f;
                    subsystemPickables.AddPickable(slotValue, num, GameWidget.ActiveCamera.ViewPosition, value, null);
                }
            }
        }
Пример #3
0
 public static void Load(Project Project)
 {
     if (LoadedProject)
     {
         return;
     }
     SubsystemGameInfo                = Project.FindSubsystem <SubsystemGameInfo>(true);
     SubsystemAudio                   = Project.FindSubsystem <SubsystemAudio>(true);
     SubsystemBodies                  = Project.FindSubsystem <SubsystemBodies>(true);
     SubsystemTime                    = Project.FindSubsystem <SubsystemTime>(true);
     SubsystemItemsScanner            = Project.FindSubsystem <SubsystemItemsScanner>(true);
     SubsystemMovingBlocks            = Project.FindSubsystem <SubsystemMovingBlocks>(true);
     SubsystemBlockEntities           = Project.FindSubsystem <SubsystemBlockEntities>(true);
     SubsystemExplosions              = Project.FindSubsystem <SubsystemExplosions>(true);
     SubsystemCollapsingBlockBehavior = Project.FindSubsystem <SubsystemCollapsingBlockBehavior>(true);
     SubsystemPickables               = Project.FindSubsystem <SubsystemPickables>(true);
     SubsystemProjectiles             = Project.FindSubsystem <SubsystemProjectiles>(true);
     Terrain       = (SubsystemTerrain = Project.FindSubsystem <SubsystemTerrain>(true)).Terrain;
     LoadedProject = true;
 }
Пример #4
0
 public override void Load(ValuesDictionary valuesDictionary)
 {
     m_subsystemViews                = base.Project.FindSubsystem <SubsystemGameWidgets>(throwOnError: true);
     SubsystemGameInfo               = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
     m_subsystemParticles            = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true);
     m_subsystemPickables            = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);
     m_subsystemBlockBehaviors       = base.Project.FindSubsystem <SubsystemBlockBehaviors>(throwOnError: true);
     SubsystemAnimatedTextures       = base.Project.FindSubsystem <SubsystemAnimatedTextures>(throwOnError: true);
     SubsystemFurnitureBlockBehavior = base.Project.FindSubsystem <SubsystemFurnitureBlockBehavior>(throwOnError: true);
     SubsystemPalette                = base.Project.FindSubsystem <SubsystemPalette>(throwOnError: true);
     Terrain                = new Terrain();
     TerrainRenderer        = new TerrainRenderer(this);
     TerrainUpdater         = new TerrainUpdater(this);
     TerrainSerializer      = new TerrainSerializer22(Terrain, SubsystemGameInfo.DirectoryName);
     BlockGeometryGenerator = new BlockGeometryGenerator(Terrain, this, base.Project.FindSubsystem <SubsystemElectricity>(throwOnError: true), SubsystemFurnitureBlockBehavior, base.Project.FindSubsystem <SubsystemMetersBlockBehavior>(throwOnError: true), SubsystemPalette);
     if (string.CompareOrdinal(SubsystemGameInfo.WorldSettings.OriginalSerializationVersion, "2.1") <= 0)
     {
         TerrainGenerationMode terrainGenerationMode = SubsystemGameInfo.WorldSettings.TerrainGenerationMode;
         if (terrainGenerationMode == TerrainGenerationMode.FlatContinent || terrainGenerationMode == TerrainGenerationMode.FlatIsland)
         {
             TerrainContentsGenerator = new TerrainContentsGeneratorFlat(this);
         }
         else
         {
             TerrainContentsGenerator = new TerrainContentsGenerator21(this);
         }
     }
     else
     {
         TerrainGenerationMode terrainGenerationMode2 = SubsystemGameInfo.WorldSettings.TerrainGenerationMode;
         if (terrainGenerationMode2 == TerrainGenerationMode.FlatContinent || terrainGenerationMode2 == TerrainGenerationMode.FlatIsland)
         {
             TerrainContentsGenerator = new TerrainContentsGeneratorFlat(this);
         }
         else
         {
             TerrainContentsGenerator = new TerrainContentsGenerator22(this);
         }
     }
 }
Пример #5
0
        public override void Load(ValuesDictionary valuesDictionary)
        {
            base.Load(valuesDictionary);
            m_subsystemAudio          = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
            m_subsystemSoundMaterials = base.Project.FindSubsystem <SubsystemSoundMaterials>(throwOnError: true);
            m_subsystemItemsScanner   = base.Project.FindSubsystem <SubsystemItemsScanner>(throwOnError: true);
            m_subsystemGameInfo       = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
            m_subsystemPickables      = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);
            m_subsystemParticles      = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true);
            ValuesDictionary value = valuesDictionary.GetValue <ValuesDictionary>("FurnitureDesigns");

            foreach (FurnitureDesign item in LoadFurnitureDesigns(base.SubsystemTerrain, value))
            {
                m_furnitureDesigns[item.Index] = item;
            }
            foreach (ValuesDictionary item2 in valuesDictionary.GetValue <ValuesDictionary>("FurnitureSets").Values.Where((object v) => v is ValuesDictionary))
            {
                string       value2       = item2.GetValue <string>("Name");
                string       value3       = item2.GetValue <string>("ImportedFrom", null);
                string       value4       = item2.GetValue <string>("Indices");
                int[]        array        = HumanReadableConverter.ValuesListFromString <int>(';', value4);
                FurnitureSet furnitureSet = new FurnitureSet
                {
                    Name         = value2,
                    ImportedFrom = value3
                };
                m_furnitureSets.Add(furnitureSet);
                int[] array2 = array;
                foreach (int num in array2)
                {
                    if (num >= 0 && num < m_furnitureDesigns.Length && m_furnitureDesigns[num] != null)
                    {
                        m_furnitureDesigns[num].FurnitureSet = furnitureSet;
                    }
                }
            }
            m_subsystemItemsScanner.ItemsScanned += GarbageCollectDesigns;
        }
Пример #6
0
 public override void Load(ValuesDictionary valuesDictionary)
 {
     base.Load(valuesDictionary);
     m_subsystemPickables = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);
 }
        public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
        {
            m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
            m_subsystemTerrain     = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
            m_subsystemPickables   = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);
            m_subsystemAudio       = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
            m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
            m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
            EggBlock eggBlock = (EggBlock)BlocksManager.Blocks[118];

            m_layFrequency = valuesDictionary.GetValue <float>("LayFrequency");
            m_eggType      = eggBlock.GetEggTypeByCreatureTemplateName(base.Entity.ValuesDictionary.DatabaseObject.Name);
            m_stateMachine.AddState("Inactive", null, delegate
            {
                if (IsActive)
                {
                    m_stateMachine.TransitionTo("Move");
                }
            }, null);
            m_stateMachine.AddState("Stuck", delegate
            {
                m_stateMachine.TransitionTo("Move");
            }, null, null);
            m_stateMachine.AddState("Move", delegate
            {
                Vector3 position2 = m_componentCreature.ComponentBody.Position;
                float num         = 5f;
                Vector3 value3    = position2 + new Vector3(num * m_random.Float(-1f, 1f), 0f, num * m_random.Float(-1f, 1f));
                value3.Y          = m_subsystemTerrain.Terrain.GetTopHeight(Terrain.ToCell(value3.X), Terrain.ToCell(value3.Z)) + 1;
                m_componentPathfinding.SetDestination(value3, m_random.Float(0.4f, 0.6f), 0.5f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
            }, delegate
            {
                if (!m_componentPathfinding.Destination.HasValue)
                {
                    m_stateMachine.TransitionTo("Lay");
                }
                else if (m_componentPathfinding.IsStuck)
                {
                    if (m_random.Float(0f, 1f) < 0.5f)
                    {
                        m_stateMachine.TransitionTo("Stuck");
                    }
                    else
                    {
                        m_importanceLevel = 0f;
                    }
                }
            }, null);
            m_stateMachine.AddState("Lay", delegate
            {
                m_layTime = 0f;
            }, delegate
            {
                if (m_eggType != null)
                {
                    m_layTime += m_dt;
                    if (m_componentCreature.ComponentBody.StandingOnValue.HasValue)
                    {
                        m_componentCreature.ComponentLocomotion.LookOrder = new Vector2(0f, 0.25f * (float)MathUtils.Sin(20.0 * m_subsystemTime.GameTime) + m_layTime / 3f) - m_componentCreature.ComponentLocomotion.LookAngles;
                        if (m_layTime >= 3f)
                        {
                            m_importanceLevel = 0f;
                            int value         = Terrain.MakeBlockValue(118, 0, EggBlock.SetIsLaid(EggBlock.SetEggType(0, m_eggType.EggTypeIndex), isLaid: true));
                            Matrix matrix     = m_componentCreature.ComponentBody.Matrix;
                            Vector3 position  = 0.5f * (m_componentCreature.ComponentBody.BoundingBox.Min + m_componentCreature.ComponentBody.BoundingBox.Max);
                            Vector3 value2    = 3f * Vector3.Normalize(-matrix.Forward + 0.1f * matrix.Up + 0.2f * m_random.Float(-1f, 1f) * matrix.Right);
                            m_subsystemPickables.AddPickable(value, 1, position, value2, null);
                            m_subsystemAudio.PlaySound("Audio/EggLaid", 1f, m_random.Float(-0.1f, 0.1f), position, 2f, autoDelay: true);
                        }
                    }
                    else if (m_layTime >= 3f)
                    {
                        m_importanceLevel = 0f;
                    }
                }
                else
                {
                    m_importanceLevel = 0f;
                }
            }, null);
        }
Пример #8
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemPickables   = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_foodFactors          = new float[EnumUtils.GetEnumValues(typeof(FoodType)).Max() + 1];
     foreach (KeyValuePair <string, object> item in valuesDictionary.GetValue <ValuesDictionary>("FoodFactors"))
     {
         FoodType foodType = (FoodType)Enum.Parse(typeof(FoodType), item.Key, ignoreCase: false);
         m_foodFactors[(int)foodType] = (float)item.Value;
     }
     m_subsystemPickables.PickableAdded += delegate(Pickable pickable)
     {
         if (TryAddPickable(pickable) && m_pickable == null)
         {
             m_pickable = pickable;
         }
     };
     m_subsystemPickables.PickableRemoved += delegate(Pickable pickable)
     {
         m_pickables.Remove(pickable);
         if (m_pickable == pickable)
         {
             m_pickable = null;
         }
     };
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
         m_pickable        = null;
     }, delegate
     {
         if (m_satiation < 1f)
         {
             if (m_pickable == null)
             {
                 if (m_subsystemTime.GameTime > m_nextFindPickableTime)
                 {
                     m_nextFindPickableTime = m_subsystemTime.GameTime + (double)m_random.Float(2f, 4f);
                     m_pickable             = FindPickable(m_componentCreature.ComponentBody.Position);
                 }
             }
             else
             {
                 m_importanceLevel = m_random.Float(5f, 10f);
             }
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Move");
             m_blockedCount = 0;
         }
     }, null);
     m_stateMachine.AddState("Move", delegate
     {
         if (m_pickable != null)
         {
             float speed = (m_satiation == 0f) ? m_random.Float(0.5f, 0.7f) : 0.5f;
             int maxPathfindingPositions = (m_satiation == 0f) ? 1000 : 500;
             float num2 = Vector3.Distance(m_componentCreature.ComponentCreatureModel.EyePosition, m_componentCreature.ComponentBody.Position);
             m_componentPathfinding.SetDestination(m_pickable.Position, speed, 1f + num2, maxPathfindingPositions, useRandomMovements: true, ignoreHeightDifference: false, raycastDestination: true, null);
             if (m_random.Float(0f, 1f) < 0.66f)
             {
                 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true);
             }
         }
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else if (m_pickable == null)
         {
             m_importanceLevel = 0f;
         }
         else if (m_componentPathfinding.IsStuck)
         {
             m_importanceLevel = 0f;
             m_satiation      += 0.75f;
         }
         else if (!m_componentPathfinding.Destination.HasValue)
         {
             m_stateMachine.TransitionTo("Eat");
         }
         else if (Vector3.DistanceSquared(m_componentPathfinding.Destination.Value, m_pickable.Position) > 0.0625f)
         {
             m_stateMachine.TransitionTo("PickableMoved");
         }
         if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true);
         }
         if (m_pickable != null)
         {
             m_componentCreature.ComponentCreatureModel.LookAtOrder = m_pickable.Position;
         }
         else
         {
             m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
         }
     }, null);
     m_stateMachine.AddState("PickableMoved", null, delegate
     {
         if (m_pickable != null)
         {
             m_componentCreature.ComponentCreatureModel.LookAtOrder = m_pickable.Position;
         }
         if (m_subsystemTime.PeriodicGameTimeEvent(0.25, (double)(GetHashCode() % 100) * 0.01))
         {
             m_stateMachine.TransitionTo("Move");
         }
     }, null);
     m_stateMachine.AddState("Eat", delegate
     {
         m_eatTime     = m_random.Float(4f, 5f);
         m_blockedTime = 0f;
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         if (m_pickable == null)
         {
             m_importanceLevel = 0f;
         }
         if (m_pickable != null)
         {
             if (Vector3.DistanceSquared(new Vector3(m_componentCreature.ComponentCreatureModel.EyePosition.X, m_componentCreature.ComponentBody.Position.Y, m_componentCreature.ComponentCreatureModel.EyePosition.Z), m_pickable.Position) < 0.640000045f)
             {
                 m_eatTime    -= m_subsystemTime.GameTimeDelta;
                 m_blockedTime = 0f;
                 if (m_eatTime <= 0.0)
                 {
                     m_satiation     += 1f;
                     m_pickable.Count = MathUtils.Max(m_pickable.Count - 1, 0);
                     if (m_pickable.Count == 0)
                     {
                         m_pickable.ToRemove = true;
                         m_importanceLevel   = 0f;
                     }
                     else if (m_random.Float(0f, 1f) < 0.5f)
                     {
                         m_importanceLevel = 0f;
                     }
                 }
             }
             else
             {
                 float num = Vector3.Distance(m_componentCreature.ComponentCreatureModel.EyePosition, m_componentCreature.ComponentBody.Position);
                 m_componentPathfinding.SetDestination(m_pickable.Position, 0.3f, 0.5f + num, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
                 m_blockedTime += m_subsystemTime.GameTimeDelta;
             }
             if (m_blockedTime > 3f)
             {
                 m_blockedCount++;
                 if (m_blockedCount >= 3)
                 {
                     m_importanceLevel = 0f;
                     m_satiation      += 0.75f;
                 }
                 else
                 {
                     m_stateMachine.TransitionTo("Move");
                 }
             }
         }
         m_componentCreature.ComponentCreatureModel.FeedOrder = true;
         if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true);
         }
         if (m_random.Float(0f, 1f) < 1.5f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(2f);
         }
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }