Exemple #1
0
        public static void OnCharacterKilled(
            ICharacter attackerCharacter,
            ICharacter targetCharacter,
            IProtoSkill protoSkill)
        {
            if (attackerCharacter is null ||
                targetCharacter is null)
            {
                return;
            }

            Api.Logger.Info("Killed " + targetCharacter, attackerCharacter);
            Api.SafeInvoke(
                () => CharacterKilled?.Invoke(attackerCharacter, targetCharacter));

            if (attackerCharacter.IsNpc ||
                !targetCharacter.IsNpc)
            {
                return;
            }

            var playerCharacterSkills = attackerCharacter.SharedGetSkills();

            // give hunting skill experience for mob kill
            var huntXP = SkillHunting.ExperienceForKill;

            huntXP *= ((IProtoCharacterMob)targetCharacter.ProtoGameObject).MobKillExperienceMultiplier;
            if (huntXP > 0)
            {
                playerCharacterSkills.ServerAddSkillExperience <SkillHunting>(huntXP);
            }

            if (protoSkill is ProtoSkillWeapons protoSkillWeapon)
            {
                // give weapon experience for kill
                protoSkillWeapon.ServerOnKill(playerCharacterSkills, killedCharacter: targetCharacter);
            }

            if (!WorldObjectClaimSystem.SharedIsEnabled)
            {
                return;
            }

            // try claim the corpse for the attacker player
            using var tempListCorpses = Api.Shared.GetTempList <IStaticWorldObject>();
            Api.GetProtoEntity <ObjectCorpse>()
            .GetAllGameObjects(tempListCorpses.AsList());
            foreach (var worldObjectCorpse in tempListCorpses.AsList())
            {
                if (targetCharacter.Id
                    == ObjectCorpse.GetPublicState(worldObjectCorpse).DeadCharacterId)
                {
                    WorldObjectClaimSystem.ServerTryClaim(worldObjectCorpse,
                                                          attackerCharacter,
                                                          WorldObjectClaimDuration.CreatureCorpse);
                    return;
                }
            }
        }
Exemple #2
0
        public void OnHitPointsChanged(int hitPointsChange)
        {
            Stats.CurrentHitPoints = Mathf.Max(0, Mathf.Min(Stats.CurrentHitPoints + hitPointsChange, Stats.HitPoints));

            Debug.Log($"Character: {Stats.Id}" + " received " + hitPointsChange + " amount of dmg");

            HitPointsChanged.Invoke(hitPointsChange);

            if (Stats.CurrentHitPoints == 0)
            {
                CharacterKilled.Invoke();
            }
        }
Exemple #3
0
        public static void OnCharacterKilled(
            ICharacter targetCharacter,
            ICharacter attackerCharacter,
            IItem weapon,
            IProtoItemWeapon protoWeapon)
        {
            // killed!
            Api.Logger.Important(
                $"Character killed: {targetCharacter} by {attackerCharacter} with {weapon?.ToString() ?? protoWeapon?.ToString()}");

            Api.SafeInvoke(
                () => CharacterKilled?.Invoke(attackerCharacter, targetCharacter));
        }
    private void OnCollisionEnter(Collision collision)
    {
        if ((_opponentLayer & 1 << collision.gameObject.layer) == 1 << collision.gameObject.layer)
        {
            Debug.Log("IsStomping: " + IsStompingEnemy());

            if (!IsStompingEnemy( ))
            {
                CharacterKilled.Invoke( );
            }
        }
        else if (collision.gameObject.tag == "KillVolume")
        {
            CharacterKilled.Invoke( );
        }
        else if (collision.gameObject.tag == "Castle")
        {
            CastleTouched.Invoke( );
        }
    }
        public static void OnCharacterKilled(
            ICharacter attackerCharacter,
            ICharacter targetCharacter,
            IProtoSkill protoSkill)
        {
            if (attackerCharacter is null ||
                targetCharacter is null)
            {
                return;
            }

            Api.Logger.Info("Killed " + targetCharacter, attackerCharacter);
            Api.SafeInvoke(
                () => CharacterKilled?.Invoke(attackerCharacter, targetCharacter));

            if (attackerCharacter.IsNpc ||
                !targetCharacter.IsNpc)
            {
                return;
            }

            var playerCharacterSkills = attackerCharacter.SharedGetSkills();

            // give hunting skill experience for mob kill
            var huntXP = SkillHunting.ExperienceForKill;

            huntXP *= ((IProtoCharacterMob)targetCharacter.ProtoGameObject).MobKillExperienceMultiplier;
            if (huntXP > 0)
            {
                playerCharacterSkills.ServerAddSkillExperience <SkillHunting>(huntXP);
            }

            if (protoSkill is ProtoSkillWeapons protoSkillWeapon)
            {
                // give weapon experience for kill
                protoSkillWeapon.ServerOnKill(playerCharacterSkills, killedCharacter: targetCharacter);
            }
        }
    /// <summary>
    /// Done to avoid racing condition with Player's stomping logic that gave rise to player & enemy both dying.
    /// </summary>
    /// <returns></returns>
    IEnumerator KillCharacter( )
    {
        yield return(new WaitForEndOfFrame( ));

        CharacterKilled.Invoke( );
    }