private void _removeDestructible(DestructibleComponent destructibleComponent)
        {
            var position = destructibleComponent.position;

            var bounds = _destructiblesTilemap.GetBoundsLocal(position);

            _destructiblesTilemap.SetTile(position, null);
        }
Esempio n. 2
0
        public PlayerObject(long objectId, string name) : base(WorldServer.Server)
        {
            ObjectId = objectId;
            Name     = name;
            Lot      = 1;

            Components.Add(ControllablePhysicsComponent = new ControllablePhysicsComponent());
            Components.Add(DestructibleComponent        = new DestructibleComponent());
            Components.Add(CharacterComponent           = new CharacterComponent());
            Components.Add(InventoryComponent           = new InventoryComponent());
            Components.Add(SkillComponent   = new SkillComponent());
            Components.Add(RenderComponent  = new RenderComponent());
            Components.Add(Index36Component = new Index36Component());
        }
        private void _createDestructible(Vector3Int position)
        {
            var entity         = _pool.CreateEntity();
            var actorComponent = new ActorComponent()
            {
                health = 10
            };
            var destructibleComponent = new DestructibleComponent()
            {
                position = position
            };

            entity.AddComponent(actorComponent);
            entity.AddComponent(destructibleComponent);
        }
Esempio n. 4
0
        private void AddDrop()
        {
            Debug.Log("Adding Drop...");

            var destroyableComponent = Object.Components.First(
                c => c.ComponentType == ReplicaComponentsId.DestructibleComponent
                );

            var comp = new DestructibleComponent(destroyableComponent.ComponentRow);

            var matrix = NewRow(LootMatrixDbTable);

            LootMatrixDbTable.AppendRow(matrix);

            var managedMatrix = new LootMatrix(matrix)
            {
                LootMatrixIndex = comp.LootMatrixIndex,
                id        = LootMatrixDbTable.Rows.Select(r => (int)r.Fields[6].Value).Max() + 1,
                percent   = 100,
                minToDrop = 1,
                maxToDrop = 1
            };

            var lootIndex = LootDbTable.Rows.Select(r => (int)r.Fields[1].Value).Max() + 1;

            managedMatrix.LootTableIndex = lootIndex;

            var loot = NewRow(LootDbTable);

            LootDbTable.AppendRow(loot);

            var managedLoot = new LootTable(loot)
            {
                LootTableIndex = lootIndex,
                id             = LootDbTable.Rows.Select(r => (int)r.Fields[2].Value).Max() + 1
            };

            SetupLoot(comp.LootMatrixIndex);
        }
Esempio n. 5
0
 public void AddThresholdsToList(EntityUid _, DestructibleComponent comp, DamageThresholdReached args)
 {
     ThresholdsReached.Add(args);
 }
Esempio n. 6
0
        public async Task Test()
        {
            var server = StartServer(new ServerContentIntegrationOption
            {
                ExtraPrototypes = Prototypes
            });

            await server.WaitIdleAsync();

            var sEntityManager       = server.ResolveDependency <IEntityManager>();
            var sMapManager          = server.ResolveDependency <IMapManager>();
            var sPrototypeManager    = server.ResolveDependency <IPrototypeManager>();
            var sEntitySystemManager = server.ResolveDependency <IEntitySystemManager>();

            EntityUid                      sDestructibleEntity          = default;
            DamageableComponent            sDamageableComponent         = null;
            DestructibleComponent          sDestructibleComponent       = null;
            TestDestructibleListenerSystem sTestThresholdListenerSystem = null;
            DamageableSystem               sDamageableSystem            = null;

            await server.WaitPost(() =>
            {
                var gridId      = GetMainGrid(sMapManager).GridEntityId;
                var coordinates = new EntityCoordinates(gridId, 0, 0);

                sDestructibleEntity    = sEntityManager.SpawnEntity(DestructibleEntityId, coordinates);
                sDamageableComponent   = IoCManager.Resolve <IEntityManager>().GetComponent <DamageableComponent>(sDestructibleEntity);
                sDestructibleComponent = IoCManager.Resolve <IEntityManager>().GetComponent <DestructibleComponent>(sDestructibleEntity);

                sTestThresholdListenerSystem = sEntitySystemManager.GetEntitySystem <TestDestructibleListenerSystem>();
                sTestThresholdListenerSystem.ThresholdsReached.Clear();

                sDamageableSystem = sEntitySystemManager.GetEntitySystem <DamageableSystem>();
            });

            await server.WaitRunTicks(5);

            await server.WaitAssertion(() =>
            {
                Assert.IsEmpty(sTestThresholdListenerSystem.ThresholdsReached);
            });

            await server.WaitAssertion(() =>
            {
                var bluntDamage = new DamageSpecifier(sPrototypeManager.Index <DamageTypePrototype>("TestBlunt"), 10);

                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage, true);

                // No thresholds reached yet, the earliest one is at 20 damage
                Assert.IsEmpty(sTestThresholdListenerSystem.ThresholdsReached);

                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage, true);

                // Only one threshold reached, 20
                Assert.That(sTestThresholdListenerSystem.ThresholdsReached.Count, Is.EqualTo(1));

                // Threshold 20
                var msg       = sTestThresholdListenerSystem.ThresholdsReached[0];
                var threshold = msg.Threshold;

                // Check that it matches the YAML prototype
                Assert.That(threshold.Behaviors, Is.Empty);
                Assert.NotNull(threshold.Trigger);
                Assert.That(threshold.Triggered, Is.True);

                sTestThresholdListenerSystem.ThresholdsReached.Clear();

                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage * 3, true);

                // One threshold reached, 50, since 20 already triggered before and it has not been healed below that amount
                Assert.That(sTestThresholdListenerSystem.ThresholdsReached.Count, Is.EqualTo(1));

                // Threshold 50
                msg       = sTestThresholdListenerSystem.ThresholdsReached[0];
                threshold = msg.Threshold;

                // Check that it matches the YAML prototype
                Assert.That(threshold.Behaviors, Has.Count.EqualTo(3));

                var soundThreshold = (PlaySoundBehavior)threshold.Behaviors[0];
                var spawnThreshold = (SpawnEntitiesBehavior)threshold.Behaviors[1];
                var actsThreshold  = (DoActsBehavior)threshold.Behaviors[2];

                Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
                Assert.That(soundThreshold.Sound.GetSound(), Is.EqualTo("/Audio/Effects/woodhit.ogg"));
                Assert.That(spawnThreshold.Spawn, Is.Not.Null);
                Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
                Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
                Assert.NotNull(threshold.Trigger);
                Assert.That(threshold.Triggered, Is.True);

                sTestThresholdListenerSystem.ThresholdsReached.Clear();

                // Damage for 50 again, up to 100 now
                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage * 5, true);

                // No thresholds reached as they weren't healed below the trigger amount
                Assert.IsEmpty(sTestThresholdListenerSystem.ThresholdsReached);

                // Set damage to 0
                sDamageableSystem.SetAllDamage(sDamageableComponent, 0);

                // Damage for 100, up to 100
                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage * 10, true);

                // Two thresholds reached as damage increased past the previous, 20 and 50
                Assert.That(sTestThresholdListenerSystem.ThresholdsReached.Count, Is.EqualTo(2));

                sTestThresholdListenerSystem.ThresholdsReached.Clear();

                // Heal the entity for 40 damage, down to 60
                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage * -4, true);

                // Thresholds don't work backwards
                Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty);

                // Damage for 10, up to 70
                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage, true);

                // Not enough healing to de-trigger a threshold
                Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty);

                // Heal by 30, down to 40
                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage * -3, true);

                // Thresholds don't work backwards
                Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty);

                // Damage up to 50 again
                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage, true);

                // The 50 threshold should have triggered again, after being healed
                Assert.That(sTestThresholdListenerSystem.ThresholdsReached.Count, Is.EqualTo(1));

                msg       = sTestThresholdListenerSystem.ThresholdsReached[0];
                threshold = msg.Threshold;

                // Check that it matches the YAML prototype
                Assert.That(threshold.Behaviors, Has.Count.EqualTo(3));

                soundThreshold = (PlaySoundBehavior)threshold.Behaviors[0];
                spawnThreshold = (SpawnEntitiesBehavior)threshold.Behaviors[1];
                actsThreshold  = (DoActsBehavior)threshold.Behaviors[2];

                // Check that it matches the YAML prototype
                Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
                Assert.That(soundThreshold.Sound.GetSound(), Is.EqualTo("/Audio/Effects/woodhit.ogg"));
                Assert.That(spawnThreshold.Spawn, Is.Not.Null);
                Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
                Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
                Assert.NotNull(threshold.Trigger);
                Assert.That(threshold.Triggered, Is.True);

                // Reset thresholds reached
                sTestThresholdListenerSystem.ThresholdsReached.Clear();

                // Heal all damage
                sDamageableSystem.SetAllDamage(sDamageableComponent, 0);

                // Damage up to 50
                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage * 5, true);

                // Check that the total damage matches
                Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50)));

                // Both thresholds should have triggered
                Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Has.Exactly(2).Items);

                // Verify the first one, should be the lowest one (20)
                msg         = sTestThresholdListenerSystem.ThresholdsReached[0];
                var trigger = (DamageTrigger)msg.Threshold.Trigger;
                Assert.NotNull(trigger);
                Assert.That(trigger.Damage, Is.EqualTo(20));

                threshold = msg.Threshold;

                // Check that it matches the YAML prototype
                Assert.That(threshold.Behaviors, Is.Empty);

                // Verify the second one, should be the highest one (50)
                msg     = sTestThresholdListenerSystem.ThresholdsReached[1];
                trigger = (DamageTrigger)msg.Threshold.Trigger;
                Assert.NotNull(trigger);
                Assert.That(trigger.Damage, Is.EqualTo(50));

                threshold = msg.Threshold;

                Assert.That(threshold.Behaviors, Has.Count.EqualTo(3));

                soundThreshold = (PlaySoundBehavior)threshold.Behaviors[0];
                spawnThreshold = (SpawnEntitiesBehavior)threshold.Behaviors[1];
                actsThreshold  = (DoActsBehavior)threshold.Behaviors[2];

                // Check that it matches the YAML prototype
                Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
                Assert.That(soundThreshold.Sound.GetSound(), Is.EqualTo("/Audio/Effects/woodhit.ogg"));
                Assert.That(spawnThreshold.Spawn, Is.Not.Null);
                Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
                Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
                Assert.NotNull(threshold.Trigger);
                Assert.That(threshold.Triggered, Is.True);

                // Reset thresholds reached
                sTestThresholdListenerSystem.ThresholdsReached.Clear();

                // Heal the entity completely
                sDamageableSystem.SetAllDamage(sDamageableComponent, 0);

                // Check that the entity has 0 damage
                Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));

                // Set both thresholds to only trigger once
                foreach (var destructibleThreshold in sDestructibleComponent.Thresholds)
                {
                    Assert.NotNull(destructibleThreshold.Trigger);
                    destructibleThreshold.TriggersOnce = true;
                }

                // Damage the entity up to 50 damage again
                sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage * 5, true);

                // Check that the total damage matches
                Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50)));

                // No thresholds should have triggered as they were already triggered before, and they are set to only trigger once
                Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty);

                // Set both thresholds to trigger multiple times
                foreach (var destructibleThreshold in sDestructibleComponent.Thresholds)
                {
                    Assert.NotNull(destructibleThreshold.Trigger);
                    destructibleThreshold.TriggersOnce = false;
                }

                // Check that the total damage matches
                Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50)));

                // They shouldn't have been triggered by changing TriggersOnce
                Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty);
            });
        }
        public async Task Test()
        {
            var server = StartServerDummyTicker(new ServerContentIntegrationOption
            {
                ExtraPrototypes  = Prototypes,
                ContentBeforeIoC = () =>
                {
                    IoCManager.Resolve <IComponentFactory>().RegisterClass <TestThresholdListenerComponent>();
                }
            });

            await server.WaitIdleAsync();

            var sEntityManager = server.ResolveDependency <IEntityManager>();
            var sMapManager    = server.ResolveDependency <IMapManager>();

            IEntity sDestructibleEntity;
            IDamageableComponent           sDamageableComponent        = null;
            DestructibleComponent          sDestructibleComponent      = null;
            TestThresholdListenerComponent sThresholdListenerComponent = null;

            await server.WaitPost(() =>
            {
                var mapId       = new MapId(1);
                var coordinates = new MapCoordinates(0, 0, mapId);
                sMapManager.CreateMap(mapId);

                sDestructibleEntity         = sEntityManager.SpawnEntity(DestructibleEntityId, coordinates);
                sDamageableComponent        = sDestructibleEntity.GetComponent <IDamageableComponent>();
                sDestructibleComponent      = sDestructibleEntity.GetComponent <DestructibleComponent>();
                sThresholdListenerComponent = sDestructibleEntity.GetComponent <TestThresholdListenerComponent>();
            });

            await server.WaitRunTicks(5);

            await server.WaitAssertion(() =>
            {
                Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
            });

            await server.WaitAssertion(() =>
            {
                Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));

                // No thresholds reached yet, the earliest one is at 20 damage
                Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);

                Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));

                // Only one threshold reached, 20
                Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));

                // Threshold 20
                var msg       = sThresholdListenerComponent.ThresholdsReached[0];
                var threshold = msg.Threshold;

                // Check that it matches the YAML prototype
                Assert.That(threshold.Behaviors, Is.Empty);
                Assert.NotNull(threshold.Trigger);
                Assert.That(threshold.Triggered, Is.True);

                sThresholdListenerComponent.ThresholdsReached.Clear();

                Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 30, true));

                // One threshold reached, 50, since 20 already triggered before and it has not been healed below that amount
                Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));

                // Threshold 50
                msg       = sThresholdListenerComponent.ThresholdsReached[0];
                threshold = msg.Threshold;

                // Check that it matches the YAML prototype
                Assert.That(threshold.Behaviors, Has.Count.EqualTo(3));

                var soundThreshold = (PlaySoundBehavior)threshold.Behaviors[0];
                var spawnThreshold = (SpawnEntitiesBehavior)threshold.Behaviors[1];
                var actsThreshold  = (DoActsBehavior)threshold.Behaviors[2];

                Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
                Assert.That(soundThreshold.Sound, Is.EqualTo("/Audio/Effects/woodhit.ogg"));
                Assert.That(spawnThreshold.Spawn, Is.Not.Null);
                Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
                Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
                Assert.NotNull(threshold.Trigger);
                Assert.That(threshold.Triggered, Is.True);

                sThresholdListenerComponent.ThresholdsReached.Clear();

                // Damage for 50 again, up to 100 now
                Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 50, true));

                // No thresholds reached as they weren't healed below the trigger amount
                Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);

                // Heal down to 0
                sDamageableComponent.Heal();

                // Damage for 100, up to 100
                Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 100, true));

                // Two thresholds reached as damage increased past the previous, 20 and 50
                Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(2));

                sThresholdListenerComponent.ThresholdsReached.Clear();

                // Heal the entity for 40 damage, down to 60
                sDamageableComponent.ChangeDamage(DamageType.Blunt, -40, true);

                // Thresholds don't work backwards
                Assert.That(sThresholdListenerComponent.ThresholdsReached, Is.Empty);

                // Damage for 10, up to 70
                sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true);

                // Not enough healing to de-trigger a threshold
                Assert.That(sThresholdListenerComponent.ThresholdsReached, Is.Empty);

                // Heal by 30, down to 40
                sDamageableComponent.ChangeDamage(DamageType.Blunt, -30, true);

                // Thresholds don't work backwards
                Assert.That(sThresholdListenerComponent.ThresholdsReached, Is.Empty);

                // Damage up to 50 again
                sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true);

                // The 50 threshold should have triggered again, after being healed
                Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));

                msg       = sThresholdListenerComponent.ThresholdsReached[0];
                threshold = msg.Threshold;

                // Check that it matches the YAML prototype
                Assert.That(threshold.Behaviors, Has.Count.EqualTo(3));

                soundThreshold = (PlaySoundBehavior)threshold.Behaviors[0];
                spawnThreshold = (SpawnEntitiesBehavior)threshold.Behaviors[1];
                actsThreshold  = (DoActsBehavior)threshold.Behaviors[2];

                // Check that it matches the YAML prototype
                Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
                Assert.That(soundThreshold.Sound, Is.EqualTo("/Audio/Effects/woodhit.ogg"));
                Assert.That(spawnThreshold.Spawn, Is.Not.Null);
                Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
                Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
                Assert.NotNull(threshold.Trigger);
                Assert.That(threshold.Triggered, Is.True);

                // Reset thresholds reached
                sThresholdListenerComponent.ThresholdsReached.Clear();

                // Heal all damage
                sDamageableComponent.Heal();

                // Damage up to 50
                sDamageableComponent.ChangeDamage(DamageType.Blunt, 50, true);

                // Check that the total damage matches
                Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));

                // Both thresholds should have triggered
                Assert.That(sThresholdListenerComponent.ThresholdsReached, Has.Exactly(2).Items);

                // Verify the first one, should be the lowest one (20)
                msg         = sThresholdListenerComponent.ThresholdsReached[0];
                var trigger = (DamageTrigger)msg.Threshold.Trigger;
                Assert.NotNull(trigger);
                Assert.That(trigger.Damage, Is.EqualTo(20));

                threshold = msg.Threshold;

                // Check that it matches the YAML prototype
                Assert.That(threshold.Behaviors, Is.Empty);

                // Verify the second one, should be the highest one (50)
                msg     = sThresholdListenerComponent.ThresholdsReached[1];
                trigger = (DamageTrigger)msg.Threshold.Trigger;
                Assert.NotNull(trigger);
                Assert.That(trigger.Damage, Is.EqualTo(50));

                threshold = msg.Threshold;

                Assert.That(threshold.Behaviors, Has.Count.EqualTo(3));

                soundThreshold = (PlaySoundBehavior)threshold.Behaviors[0];
                spawnThreshold = (SpawnEntitiesBehavior)threshold.Behaviors[1];
                actsThreshold  = (DoActsBehavior)threshold.Behaviors[2];

                // Check that it matches the YAML prototype
                Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
                Assert.That(soundThreshold.Sound, Is.EqualTo("/Audio/Effects/woodhit.ogg"));
                Assert.That(spawnThreshold.Spawn, Is.Not.Null);
                Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
                Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
                Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
                Assert.NotNull(threshold.Trigger);
                Assert.That(threshold.Triggered, Is.True);

                // Reset thresholds reached
                sThresholdListenerComponent.ThresholdsReached.Clear();

                // Heal the entity completely
                sDamageableComponent.Heal();

                // Check that the entity has 0 damage
                Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));

                // Set both thresholds to only trigger once
                foreach (var destructibleThreshold in sDestructibleComponent.Thresholds)
                {
                    Assert.NotNull(destructibleThreshold.Trigger);
                    destructibleThreshold.TriggersOnce = true;
                }

                // Damage the entity up to 50 damage again
                sDamageableComponent.ChangeDamage(DamageType.Blunt, 50, true);

                // Check that the total damage matches
                Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));

                // No thresholds should have triggered as they were already triggered before, and they are set to only trigger once
                Assert.That(sThresholdListenerComponent.ThresholdsReached, Is.Empty);

                // Set both thresholds to trigger multiple times
                foreach (var destructibleThreshold in sDestructibleComponent.Thresholds)
                {
                    Assert.NotNull(destructibleThreshold.Trigger);
                    destructibleThreshold.TriggersOnce = false;
                }

                // Check that the total damage matches
                Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));

                // They shouldn't have been triggered by changing TriggersOnce
                Assert.That(sThresholdListenerComponent.ThresholdsReached, Is.Empty);
            });
        }
Esempio n. 8
0
        private void LoadStats()
        {
            var healthInput      = Health.GetComponentInChildren <TMP_InputField>();
            var armorInput       = Armor.GetComponentInChildren <TMP_InputField>();
            var imaginationInput = Imagination.GetComponentInChildren <TMP_InputField>();

            healthInput.text      = "";
            armorInput.text       = "";
            imaginationInput.text = "";
            healthInput.onEndEdit.RemoveAllListeners();
            armorInput.onEndEdit.RemoveAllListeners();
            imaginationInput.onEndEdit.RemoveAllListeners();
            healthInput.interactable      = false;
            armorInput.interactable       = false;
            imaginationInput.interactable = false;

            var destroyableComponent = Object.Components.FirstOrDefault(
                c => c.ComponentType == ReplicaComponentsId.DestructibleComponent
                );

            if (destroyableComponent != default)
            {
                var comp = new DestructibleComponent(destroyableComponent.ComponentRow);

                try
                {
                    healthInput.text = comp.life.ToString();
                }
                catch
                {
                    healthInput.text = "0";
                }

                try
                {
                    armorInput.text = comp.armor.ToString(CultureInfo.CurrentCulture);
                }
                catch
                {
                    armorInput.text = "0";
                }

                try
                {
                    imaginationInput.text = comp.imagination.ToString();
                }
                catch
                {
                    imaginationInput.text = "0";
                }

                healthInput.onEndEdit.AddListener(s => { comp.life = int.Parse(s); });
                armorInput.onEndEdit.AddListener(s => { comp.armor = int.Parse(s); });
                imaginationInput.onEndEdit.AddListener(s => { comp.imagination = int.Parse(s); });

                healthInput.interactable      = true;
                armorInput.interactable       = true;
                imaginationInput.interactable = true;

                SetupLoot(comp.LootMatrixIndex);
            }

            var rebuildComponent = Object.Components.FirstOrDefault(
                c => c.ComponentType == ReplicaComponentsId.RebuildComponent
                );

            AddLootButton.interactable = destroyableComponent != default;

            if (rebuildComponent == default || destroyableComponent != default)
            {
                return;
            }
            {
                var comp = new RebuildComponent(rebuildComponent.ComponentRow);
                imaginationInput.text = comp.take_imagination.ToString();
                imaginationInput.onEndEdit.AddListener(s => { comp.take_imagination = int.Parse(s); });

                imaginationInput.interactable = true;
            }
        }
Esempio n. 9
0
        public void OnWorldLevelLoadCompletePacketReceive(GamePacketReceiveEvent e)
        {
            if (e.Packet is WorldLevelLoadCompletePacket)
            {
                Session session = Server.Instance.SessionManager.GetSession(e.SourceAddress, e.SourcePort);

                if (session != null)
                {
                    if (session.ActiveCharacterInfo != null)
                    {
                        WriteOnlyBinaryLdf ldfMap = new WriteOnlyBinaryLdf();

                        ldfMap.AddWideString("name", session.ActiveCharacterInfo.Name);
                        ldfMap.AddBoolean("editor_enabled", session.ActiveCharacterInfo.EditorLevel > 0);
                        ldfMap.AddInt32("editor_level", session.ActiveCharacterInfo.EditorLevel);
                        ldfMap.AddInt32("template", 1);
                        ldfMap.AddInt32("gmlevel", session.ActiveCharacterInfo.GmLevel);
                        ldfMap.AddUInt64("objid", (ulong)session.ActiveCharacterInfo.CharacterId);
                        ldfMap.AddFloat("position.x", session.ActiveCharacterInfo.Position.X);
                        ldfMap.AddFloat("position.y", session.ActiveCharacterInfo.Position.Y);
                        ldfMap.AddFloat("position.z", session.ActiveCharacterInfo.Position.Z);
                        ldfMap.AddFloat("rotation.x", session.ActiveCharacterInfo.Rotation.X);
                        ldfMap.AddFloat("rotation.y", session.ActiveCharacterInfo.Rotation.Y);
                        ldfMap.AddFloat("rotation.z", session.ActiveCharacterInfo.Rotation.Z);
                        ldfMap.AddFloat("rotation.w", session.ActiveCharacterInfo.Rotation.W);

                        ClientCreateCharacterPacket response = new ClientCreateCharacterPacket();

                        response.LdfMap = ldfMap;

                        Server.Instance.SendGamePacket(response, ClientPacketId.MSG_CLIENT_CREATE_CHARACTER, e.SourceAddress, e.SourcePort);

                        Replica character = new Replica(session.ActiveCharacterInfo.CharacterId, null, 1, 0);

                        character.Name = session.ActiveCharacterInfo.Name;

                        ControllablePhysicsComponent controllablePhysicsComponent = new ControllablePhysicsComponent();

                        controllablePhysicsComponent.Position = session.ActiveCharacterInfo.Position;
                        controllablePhysicsComponent.Rotation = session.ActiveCharacterInfo.Rotation;

                        character.AddComponent(controllablePhysicsComponent);

                        DestructibleComponent destructibleComponent = new DestructibleComponent();

                        character.AddComponent(destructibleComponent);

                        StatsComponent statsComponent = new StatsComponent();

                        statsComponent.IsSmashable = false;
                        statsComponent.FactionIds.Add(1);
                        statsComponent.CurrentHealth      = session.ActiveCharacterInfo.CurrentHealth;
                        statsComponent.CurrentArmor       = session.ActiveCharacterInfo.CurrentArmor;
                        statsComponent.CurrentImagination = session.ActiveCharacterInfo.CurrentImagination;
                        statsComponent.MaxHealth          = session.ActiveCharacterInfo.MaxHealth;
                        statsComponent.MaxArmor           = session.ActiveCharacterInfo.MaxArmor;
                        statsComponent.MaxImagination     = session.ActiveCharacterInfo.MaxImagination;

                        character.AddComponent(statsComponent);

                        CharacterComponent characterComponent = new CharacterComponent();

                        characterComponent.CharacterInfo = session.ActiveCharacterInfo;
                        characterComponent.AccountInfo   = session.ActiveAccountInfo;

                        character.AddComponent(characterComponent);

                        InventoryComponent inventoryComponent = new InventoryComponent();

                        character.AddComponent(inventoryComponent);

                        SkillComponent skillComponent = new SkillComponent();

                        character.AddComponent(skillComponent);

                        RenderComponent renderComponent = new RenderComponent();

                        character.AddComponent(renderComponent);

                        BbbComponent bbbComponent = new BbbComponent();

                        character.AddComponent(bbbComponent);

                        ReplicaManager thingManager = Server.Instance.GetReplicaManager(session.ActiveCharacterInfo.ZoneId);

                        thingManager.AddPlayer(session, character);

                        ServerDoneLoadingAllObjectGameMessage serverDoneLoadingAllObjects = new ServerDoneLoadingAllObjectGameMessage(session.ActiveCharacterInfo.CharacterId);

                        Server.Instance.SendGamePacket(serverDoneLoadingAllObjects, ClientPacketId.MSG_CLIENT_GAME_MSG, e.SourceAddress, e.SourcePort);
                    }
                    else
                    {
                        GeneralDisconnectNotifyPacket dcPacket = new GeneralDisconnectNotifyPacket();

                        dcPacket.DisconnectReason = DisconnectReason.CharacterCorruption;

                        Server.Instance.SendGamePacket(dcPacket, GeneralPacketId.MSG_SERVER_DISCONNECT_NOTIFY, e.SourceAddress, e.SourcePort);
                    }
                }
            }
        }