public override void ServerOnDestroy(ICharacter gameObject)
        {
            base.ServerOnDestroy(gameObject);
            if (!GetPublicState(gameObject).IsDead)
            {
                return;
            }

            using var tempList = Api.Shared.GetTempList <ICharacter>();
            ServerWorld.GetScopedByPlayers(gameObject, tempList);
            this.CallClient(tempList, _ => _.ClientRemote_OnCharacterMobDeath(gameObject.Position));
        }
Beispiel #2
0
        public void ServerPlaySound(ICharacter characterNpc, CharacterSound characterSound)
        {
            using var observers = Api.Shared.GetTempList <ICharacter>();

            if (characterSound != CharacterSound.Aggression)
            {
                ServerWorld.GetScopedByPlayers(characterNpc, observers);
            }
            else
            {
                // this event is propagated on a larger distance and has sound cues
                ServerWorld.GetCharactersInRadius(characterNpc.TilePosition,
                                                  observers,
                                                  radius: this.SoundEventsNetworkRadius,
                                                  onlyPlayers: true);
            }

            this.CallClient(observers.AsList(),
                            _ => _.ClientRemote_PlaySound(characterNpc,
                                                          characterNpc.TilePosition,
                                                          characterSound));
        }
        public override bool SharedOnDamage(
            WeaponFinalCache weaponCache,
            IStaticWorldObject targetObject,
            double damagePreMultiplier,
            out double obstacleBlockDamageCoef,
            out double damageApplied)
        {
            if (weaponCache.Character != null)
            {
                // damaged by character
                if (IsServer)
                {
                    // notify other characters
                    using (var tempList = Api.Shared.GetTempList <ICharacter>())
                    {
                        ServerWorld.GetScopedByPlayers(targetObject, tempList);
                        tempList.Remove(weaponCache.Character);
                        this.CallClient(tempList, _ => _.ClientRemote_OnHit());
                    }
                }
                else
                {
                    ClientOnHit();
                }
            }

            if (weaponCache.ProtoWeapon != null &&
                !(weaponCache.ProtoWeapon is IProtoItemWeaponMelee))
            {
                // hit but not damaged - only melee weapons (including pickaxes can damage this)
                obstacleBlockDamageCoef = this.ObstacleBlockDamageCoef;
                damageApplied           = 0;
                return(true);
            }

            return(base.SharedOnDamage(weaponCache,
                                       targetObject,
                                       damagePreMultiplier,
                                       out obstacleBlockDamageCoef,
                                       out damageApplied));
        }