Example #1
0
        public virtual bool TakeDamage(WIMaterialType materialType, Vector3 damagePoint, float attemptedDamage, Vector3 attemptedForce, string damageSource, out float actualDamage, out bool isDead)
        {
            actualDamage       = attemptedDamage;
            isDead             = false;
            State.TotalDamage += actualDamage;

            if (HasPlayerFocus)
            {
                GUIHud.Get.ShowProgressBar(Colors.Get.GeneralHighlightColor, Colors.Darken(Colors.Get.GenericNeutralValue), NormalizedDamage);
            }

            if (State.SpawnOnDamaage && State.TotalDamage >= State.SpawnDamageMinimum)                                          //reset
            {
                State.TotalDamage = 0f;
                //spawn a thing
                WorldItem worlditem = null;
                if (WorldItems.CloneRandomFromCategory(State.SpawnCategory, ParentChunk.AboveGroundGroup, out worlditem))
                {
                    //spit it out at the player
                    Vector3 direction = (Player.Local.Position - damagePoint).normalized * 5f;
                    worlditem.tr.parent   = ParentChunk.AboveGroundGroup.transform;
                    worlditem.tr.position = damagePoint;
                    worlditem.Props.Local.FreezeOnStartup = false;
                    worlditem.Props.Local.Transform.CopyFrom(worlditem.tr);
                    worlditem.Initialize();
                    worlditem.SetMode(WIMode.World);
                    worlditem.ApplyForce(direction, damagePoint);
                    FXManager.Get.SpawnFX(worlditem.tr, "DrawAttentionToItem");
                    worlditem.GetOrAdd <DespawnOnPlayerLeave>();
                }
            }
            return(true);
        }