protected virtual void ServerOnUse(ICharacter character, PlayerCharacterCurrentStats currentStats)
        {
            if (this.MedicalToxicity > 0)
            {
                character.ServerAddStatusEffect <StatusEffectMedicineOveruse>(intensity: this.MedicalToxicity);
            }

            if (this.StaminaRestore != 0)
            {
                currentStats.SharedSetStaminaCurrent(currentStats.StaminaCurrent + this.StaminaRestore);
            }

            if (this.HealthRestore != 0)
            {
                currentStats.ServerSetHealthCurrent(currentStats.HealthCurrent + this.HealthRestore);
            }

            if (this.FoodRestore != 0)
            {
                currentStats.ServerSetFoodCurrent(currentStats.FoodCurrent + this.FoodRestore);
            }

            if (this.WaterRestore != 0)
            {
                currentStats.ServerSetWaterCurrent(currentStats.WaterCurrent + this.WaterRestore);
            }
        }
        private static void ServerOnSuccessfulRespawn(PlayerCharacterCurrentStats stats, ICharacter character)
        {
            stats.ServerSetHealthCurrent(stats.HealthMax / 2f, overrideDeath: true);
            stats.SharedSetStaminaCurrent(stats.StaminaMax / 2f);
            stats.ServerSetFoodCurrent(stats.FoodMax / 4f);
            stats.ServerSetWaterCurrent(stats.WaterMax / 4f);

            // remove status effects flagged as removed on respawn
            foreach (var statusEffect in character.ServerEnumerateCurrentStatusEffects().ToList())
            {
                var protoStatusEffect = (IProtoStatusEffect)statusEffect.ProtoLogicObject;
                if (protoStatusEffect.IsRemovedOnRespawn)
                {
                    character.ServerRemoveStatusEffect(protoStatusEffect);
                }
            }

            // reset learning points
            var technologies = character.SharedGetTechnologies();

            technologies.ServerResetLearningPointsRemainder();

            var learningPointsRetainedAfterDeath = SharedGetLearningPointsRetainedAfterDeath(character);
            var lostLp = technologies.LearningPoints - learningPointsRetainedAfterDeath;

            if (lostLp > 0)
            {
                technologies.ServerSetLearningPoints(learningPointsRetainedAfterDeath);
                character.ServerAddSkillExperience <SkillLearning>(
                    lostLp * SkillLearning.ExperienceAddedPerLPLost);
            }

            // recreate physics (as dead character doesn't have any physics)
            character.ProtoCharacter.SharedCreatePhysics(character);

            Api.Server.Characters.SetViewScopeMode(character, isEnabled: true);

            // character is weakened after respawn for some time
            character.ServerAddStatusEffect <StatusEffectWeakened>(intensity: 0.5);
        }
Example #3
0
        protected virtual void ServerOnUse(ICharacter character, PlayerCharacterCurrentStats currentStats)
        {
            if (this.MedicalToxicity > 0)
            {
                character.ServerAddStatusEffect <StatusEffectMedicineOveruse>(intensity: this.MedicalToxicity);
            }

            if (this.StaminaRestore != 0)
            {
                currentStats.SharedSetStaminaCurrent(currentStats.StaminaCurrent + this.StaminaRestore);
            }

            if (this.HealthRestore != 0)
            {
                if (this.HealthRestore > 0)
                {
                    currentStats.ServerSetHealthCurrent(currentStats.HealthCurrent + this.HealthRestore);
                }
                else
                {
                    currentStats.ServerReduceHealth(-this.HealthRestore, this);
                }
            }

            if (this.FoodRestore != 0)
            {
                currentStats.ServerSetFoodCurrent(currentStats.FoodCurrent + this.FoodRestore);
            }

            if (this.WaterRestore != 0)
            {
                currentStats.ServerSetWaterCurrent(currentStats.WaterCurrent + this.WaterRestore);
            }

            foreach (var effect in this.Effects)
            {
                effect.Execute(new EffectActionContext(character));
            }
        }