예제 #1
0
    private void ExitCombat(Player player, NpcInstance npc, int attackType)
    {
        playerState.ExitCombat(player);
        playerState.ClearAttackTime(player, npc);

        StopAttackAnimation(player, attackType);
    }
예제 #2
0
        public void PlayerBuyItem(Player player, NpcInstance npc, int itemId, int amount)
        {
            var session = sessions.Get(player);
            var item    = gameData.GetItem(itemId);

            if (item == null)
            {
                return;
            }

            var shopInventory = session.Npcs.Inventories.GetInventory(npc.Id);

            if (shopInventory == null)
            {
                return;
            }

            var shopItem = shopInventory.GetItem(itemId);

            var totalPrice = shopItem.Price * amount;

            if (player.Coins < totalPrice)
            {
                return;
            }

            if (shopInventory.TryRemoveItem(item, amount))
            {
                player.Coins -= totalPrice;

                UpdatePlayerCoins(player);
                AddPlayerItem(player, item, amount);
                NpcTradeUpdateStock(npc);
            }
        }
예제 #3
0
        public void NpcTradeUpdateStock(NpcInstance npc)
        {
            var session       = sessions.Get(npc);
            var shopInventory = session.Npcs.Inventories.GetInventory(npc.Id);

            if (shopInventory == null)
            {
                return;
            }

            var itemCount = shopInventory.Items.Count;
            var itemIds   = new int[itemCount];
            var itemPrice = new int[itemCount];
            var itemStock = new int[itemCount];

            for (var i = 0; i < itemCount; ++i)
            {
                var item = shopInventory.Items[i];
                itemIds[i]   = item.ItemId;
                itemPrice[i] = item.Price;
                itemStock[i] = item.Amount;
            }

            foreach (var connection in connectionProvider.GetConnectedActivePlayerConnections(session))
            {
                connection.Send(new NpcTradeUpdateStock
                {
                    ItemId      = itemIds,
                    ItemPrice   = itemPrice,
                    ItemStock   = itemStock,
                    NpcServerId = npc.Id,
                    PlayerId    = connection.Player.Id
                }, SendOption.Reliable);
            }
        }
예제 #4
0
    private bool ReadyForAttack(Player player, NpcInstance npc, int attackType)
    {
        var lastAttack = playerState.GetAttackTime(player, npc);
        var timeDelta  = DateTime.UtcNow - lastAttack;

        return(timeDelta >= TimeSpan.FromMilliseconds(PlayerMeleeAttackIntervalMs));
    }
예제 #5
0
        public void OpenTradeWindow(Player player, NpcInstance npc, string shopName, ShopInventory shopInventory)
        {
            var playerConnection = connectionProvider.GetPlayerConnection(player);

            if (playerConnection == null)
            {
                return;
            }

            var itemCount = shopInventory.Items.Count;
            var itemIds   = new int[itemCount];
            var itemPrice = new int[itemCount];
            var itemStock = new int[itemCount];

            for (var i = 0; i < itemCount; ++i)
            {
                var item = shopInventory.Items[i];
                itemIds[i]   = item.ItemId;
                itemPrice[i] = item.Price;
                itemStock[i] = item.Amount;
            }

            playerConnection.Send(new NpcTradeOpenWindow
            {
                PlayerId    = player.Id,
                ItemId      = itemIds,
                ItemPrice   = itemPrice,
                ItemStock   = itemStock,
                ShopName    = shopName,
                NpcServerId = npc.Id,
            }, SendOption.Reliable);
        }
예제 #6
0
        public LongRunningAction Say(int id, string line, string customSound, string customAnimation)
        {
            SpeechLine speechLine = new SpeechLine()
            {
                Text = line
            };
            NpcInstance npc = this.LevelManager.NonPlayerCharacters[id];

            if (!string.IsNullOrEmpty(customSound))
            {
                if (speechLine.OverrideContent == null)
                {
                    speechLine.OverrideContent = new NpcActionContent();
                }
                speechLine.OverrideContent.Sound = this.LoadSound(customSound);
            }
            if (!string.IsNullOrEmpty(customAnimation))
            {
                if (speechLine.OverrideContent == null)
                {
                    speechLine.OverrideContent = new NpcActionContent();
                }
                speechLine.OverrideContent.Animation = this.LoadAnimation(npc, customAnimation);
            }
            npc.CustomSpeechLine = speechLine;
            return(new LongRunningAction((Func <float, float, bool>)((_, __) => npc.CustomSpeechLine == null)));
        }
예제 #7
0
        /// <summary>
        /// NPC
        /// </summary>
        /// <param name="texturePool"></param>
        /// <param name="npcInstance"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <returns></returns>
        public static NpcItem CreateNpcFromProperty(TexturePool texturePool, NpcInstance npcInstance, GraphicsDevice device, ref List <WzObject> usedProps)
        {
            NpcInfo npcInfo = (NpcInfo)npcInstance.BaseInfo;
            WzImage source  = npcInfo.LinkedWzImage;

            List <IDXObject> frames = new List <IDXObject>(); // All frames "stand", "speak" "blink" "hair", "angry", "wink" etc

            foreach (WzImageProperty childProperty in source.WzProperties)
            {
                WzSubProperty npcStateProperty = (WzSubProperty)childProperty;
                switch (npcStateProperty.Name)
                {
                case "info":     // info/speak/0 WzStringProperty
                {
                    break;
                }

                default:
                {
                    frames.AddRange(LoadFrames(texturePool, npcStateProperty, npcInstance.X, npcInstance.Y, device, ref usedProps));
                    break;
                }
                }
            }
            return(new NpcItem(npcInstance, frames));
        }
예제 #8
0
 public static NpcRespawn Create(NpcInstance npc, Player player)
 {
     return(new NpcRespawn
     {
         NpcServerId = npc.Id,
         PlayerId = player.Id,
     });
 }
예제 #9
0
 private bool OnNpcAfflictDamage(
     Player player,
     NpcInstance npc,
     TimeSpan totalTime,
     TimeSpan deltaTime)
 {
     return(false);
 }
예제 #10
0
        public void RespawnNpc(Player player, NpcInstance npc)
        {
            var session = sessions.Get(player);

            foreach (var connection in connectionProvider.GetConnectedActivePlayerConnections(session))
            {
                connection.Send(NpcRespawn.Create(npc, player), SendOption.Reliable);
            }
        }
예제 #11
0
        public void DamageNpc(Player player, NpcInstance npc, int damage, int health, int maxHealth)
        {
            var session = sessions.Get(player);

            foreach (var connection in connectionProvider.GetConnectedActivePlayerConnections(session))
            {
                connection.Send(NpcHealthChange.Create(npc, player, -damage, health, maxHealth), SendOption.Reliable);
            }
        }
예제 #12
0
        public void PlayAnimation(NpcInstance npc, string animation, bool enabled = true, bool trigger = false, int number = 0)
        {
            var session = sessions.Get(npc);

            foreach (var connection in connectionProvider.GetConnectedActivePlayerConnections(session))
            {
                connection.Send(NpcAnimationStateUpdate.Create(npc, animation, enabled, trigger, number), SendOption.Reliable);
            }
        }
예제 #13
0
파일: NpcState.cs 프로젝트: conankzhang/fez
        public NpcState(Game game, NpcInstance npc)
            : base(game)
        {
            this.Npc       = npc;
            this.Npc.State = this;
            foreach (NpcAction key in Util.GetValues <NpcAction>())
            {
                switch (key)
                {
                case NpcAction.None:
                case NpcAction.Walk:
                case NpcAction.Idle:
                case NpcAction.Talk:
                    continue;

                default:
                    if (!this.Npc.Actions.ContainsKey(key))
                    {
                        if (MemoryContentManager.AssetExists(string.Concat(new object[4]
                        {
                            (object)"Character Animations\\",
                            (object)this.Npc.Name,
                            (object)"\\",
                            (object)key
                        })))
                        {
                            this.Npc.Actions.Add(key, new NpcActionContent()
                            {
                                AnimationName = ((object)key).ToString()
                            });
                            continue;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            if (MemoryContentManager.AssetExists("Character Animations\\" + this.Npc.Name + "\\Metadata"))
            {
                npc.FillMetadata(ServiceHelper.Get <IContentManagerProvider>().CurrentLevel.Load <NpcMetadata>("Character Animations/" + npc.Name + "/Metadata"));
            }
            this.CanIdle    = this.Npc.Actions.ContainsKey(NpcAction.Idle);
            this.CanIdle2   = this.Npc.Actions.ContainsKey(NpcAction.Idle2);
            this.CanIdle3   = this.Npc.Actions.ContainsKey(NpcAction.Idle3);
            this.CanTalk    = this.Npc.Actions.ContainsKey(NpcAction.Talk);
            this.CanWalk    = this.Npc.Actions.ContainsKey(NpcAction.Walk);
            this.CanTurn    = this.Npc.Actions.ContainsKey(NpcAction.Turn);
            this.CanBurrow  = this.Npc.Actions.ContainsKey(NpcAction.Burrow);
            this.CanHide    = this.Npc.Actions.ContainsKey(NpcAction.Hide);
            this.CanTakeOff = this.Npc.Actions.ContainsKey(NpcAction.TakeOff);
        }
예제 #14
0
    private bool WithinDistance(Player player, NpcInstance npc, int attackType)
    {
        var playerTransform = gameData.GetTransform(player.TransformId);
        var npcTransform    = gameData.GetTransform(npc.TransformId);
        var delta           = playerTransform.GetPosition() - npcTransform.GetPosition();
        var distance        = delta.SqrtMagnitude;

        return(distance <= MeleeRange); // change depending how player attacks.
    }
예제 #15
0
    private void NpcAttack(Player player, NpcInstance npc)
    {
        var session = sessionManager.Get(player);

        playerState.EnterCombat(player, npc);
        session.Npcs.States.EnterCombat(npc, player);

        PlayAttackAnimation(npc);
        worldProcessor.SetEntityTimeout(NpcMeleeAttackIntervalMs, player, npc, OnNpcAfflictDamage);
    }
예제 #16
0
    private bool OnRespawn(Player player, NpcInstance npc, TimeSpan totalTime, TimeSpan deltaTime)
    {
        var n          = gameData.GetNpc(npc.NpcId);
        var attributes = gameData.GetAttributes(n.AttributesId);

        npc.Health    = attributes.Health;
        npc.Endurance = attributes.Endurance;
        worldProcessor.RespawnNpc(player, npc);
        return(true);
    }
예제 #17
0
        public EntityActionInvoker GetAction(NpcInstance npcInstance, int actionId)
        {
            var npc = gameData.GetNpc(npcInstance.NpcId);

            if (entityActions.TryGetValue(npc.NpcId, out var actions))
            {
                return(actions.Select(x => x.Value).FirstOrDefault(x => x.Id == actionId));
            }

            return(null);
        }
예제 #18
0
 public static NpcAnimationStateUpdate Create(NpcInstance npc, string anim, bool enabled, bool trigger, int number)
 {
     return(new NpcAnimationStateUpdate
     {
         NpcServerId = npc.Id,
         AnimationState = anim,
         Enabled = enabled,
         Trigger = trigger,
         ActionNumber = number
     });
 }
예제 #19
0
    private void PlayerAttack(Player player, NpcInstance npc, int attackType)
    {
        var session = sessionManager.Get(player);

        playerState.EnterCombat(player, npc);
        session.Npcs.States.EnterCombat(npc, player);

        playerState.UpdateAttackTime(player, npc);
        PlayAttackAnimation(player, attackType);
        worldProcessor.SetEntityTimeout(PlayerMeleeAttackIntervalMs, player, npc, OnPlayerAfflictDamage);
    }
예제 #20
0
        public NpcInstance CreateNpcInstance()
        {
            var id  = GetNextId(npcInstances.Entities);
            var npc = new NpcInstance()
            {
                Id = id
            };

            Add(npc);
            return(npc);
        }
예제 #21
0
 protected override NpcState CreateNpcState(NpcInstance npc)
 {
     if (npc.ActorType == ActorType.Owl && this.GameState.SaveData.ThisLevel.InactiveNPCs.Contains(npc.Id))
     {
         return((NpcState)null);
     }
     else
     {
         return((NpcState) new GameNpcState(this.Game, npc));
     }
 }
예제 #22
0
 public static NpcHealthChange Create(NpcInstance npc, Player player, int damage, int health, int maxHealth)
 {
     return(new NpcHealthChange
     {
         NpcServerId = npc.Id,
         PlayerId = player.Id,
         Delta = damage,
         Health = health,
         MaxHealth = maxHealth
     });
 }
예제 #23
0
        public NpcAlignment GetAlignment(Player player, NpcInstance npc)
        {
            if (alignments.TryGetValue(player.Id, out var a))
            {
                if (a.TryGetValue(npc.Id, out var alignment))
                {
                    return(alignment);
                }
            }

            return(SetAlignment(player, npc, npc.Alignment));
        }
예제 #24
0
        public NpcAlignment SetAlignment(Player player, NpcInstance npc, NpcAlignment alignment)
        {
            if (alignments.TryGetValue(player.Id, out var a))
            {
                a[npc.Id] = npc.Alignment;
                return(npc.Alignment);
            }

            alignments[player.Id] = new Dictionary <int, NpcAlignment> {
                {
                    npc.Id,
                    npc.Alignment
                }
            };

            return(alignments[player.Id][npc.Id]);
        }
예제 #25
0
 public void PlayerNpcInteraction(
     Player player, NpcInstance npc, EntityActionInvoker action, int parameterId)
 {
     if (action.Invoke(player, npc, parameterId))
     {
         foreach (var playerConnection in connectionProvider.GetAll())
         {
             playerConnection.Send(new PlayerNpcActionResponse
             {
                 PlayerId    = player.Id,
                 ActionId    = action.Id,
                 NpcServerId = npc.Id,
                 ParameterId = parameterId,
                 Status      = 1 // 0: fail, 1: success
             }, SendOption.Reliable);
         }
     }
 }
예제 #26
0
        public static NpcAdd Create(IGameData gameData, NpcInstance obj, Transform transform)
        {
            var npc   = gameData.GetNpc(obj.NpcId);
            var npcid = npc.NpcId;

            return(new NpcAdd
            {
                ServerId = obj.Id,
                NpcId = npcid,
                Level = npc.Level,
                Health = obj.Health,
                Endurance = obj.Endurance,
                Attributes = gameData.GetAttributes(npcid),
                Position = transform.GetPosition(),
                Rotation = transform.GetRotation(),
                Destination = transform.GetDestination()
            });
        }
예제 #27
0
    public static GameObject GenObject(this NpcInstance npc, GameObject parent = null)
    {
        GameObject obj = new GameObject(npc.Name);

        if (parent != null)
        {
            obj.transform.parent = parent.transform;
        }
        obj.transform.localPosition = npc.Position;

        FezUnityNpcInstance fezHolder = obj.AddComponent <FezUnityNpcInstance>();

        fezHolder.Fill(npc);
        obj.isStatic = false;

        // Fix Unity / Trixel Engine Z direction conflict
        obj.FezZ();

        return(obj);
    }
예제 #28
0
        public void PlayerSellItem(Player player, NpcInstance npc, int itemId, int amount)
        {
            var session = sessions.Get(player);
            var item    = gameData.GetItem(itemId);

            if (item == null)
            {
                return;
            }

            var inventory = playerInventoryProvider.GetInventory(player.Id);

            if (inventory == null)
            {
                return;
            }

            var shopInventory = session.Npcs.Inventories.GetInventory(npc.Id);

            if (shopInventory == null)
            {
                return;
            }

            if (inventory.HasItem(item, amount))
            {
                var shopItem = shopInventory.GetItem(item.Id);
                if (shopItem == null)
                {
                    return;
                }

                //player.Coins += shopItem.Item.Value * amount;
                player.Coins += shopItem.Price * amount;

                RemovePlayerItem(player, item, amount);
                shopInventory.AddItem(item, amount, shopItem.Price);
                NpcTradeUpdateStock(npc);
                UpdatePlayerCoins(player);
            }
        }
예제 #29
0
    private bool Invoke(
        Player player,
        NpcInstance npc,
        TimeSpan totalTime,
        TimeSpan deltaTime)
    {
        var attackType = playerState.GetAttackType(player);
        var session    = sessionManager.Get(player);

        if (!session.Npcs.States.IsEnemy(player, npc))
        {
            return(false);
        }

        if (npc.Health <= 0)
        {
            return(false);
        }

        if (!WithinDistance(player, npc, attackType))
        {
            if (totalTime.TotalMilliseconds < TotalRetryTimeMs)
            {
                worldProcessor.SetEntityTimeout(RetryTimeMs, player, npc, Invoke);
            }
            return(false);
        }

        if (!ReadyForAttack(player, npc, attackType))
        {
            return(false);
        }

        PlayerAttack(player, npc, attackType);

        NpcAttack(player, npc);

        return(false);
    }
예제 #30
0
 public override void Initialize()
 {
     base.Initialize();
     this.LevelManager.AddPlane(this.Plane = new BackgroundPlane(this.LevelMaterializer.StaticPlanesMesh, (Texture)this.CMProvider.CurrentLevel.Load <Texture2D>("Other Textures/CAPSULE"))
     {
         Rotation = this.CameraManager.Rotation,
         Loop     = false
     });
     if (this.NpcId.HasValue)
     {
         this.Npc                        = this.LevelManager.NonPlayerCharacters[this.NpcId.Value];
         this.OldPosition                = this.Npc.Position;
         this.Npc.Position               = new Vector3(487.0 / 16.0, 49f, 10f);
         this.OldDestinationOffset       = this.Npc.DestinationOffset;
         this.Npc.DestinationOffset      = new Vector3(-63.0 / 16.0, 0.0f, 0.0f);
         this.Npc.State.Scripted         = true;
         this.Npc.State.LookingDirection = HorizontalDirection.Left;
         this.Npc.State.WalkStep         = 0.0f;
         this.Npc.State.CurrentAction    = NpcAction.Idle;
         this.Npc.State.UpdateAction();
         this.Npc.State.SyncTextureMatrix();
         this.Npc.Group.Position        = this.LevelManager.NonPlayerCharacters[this.NpcId.Value].Position;
         this.CameraManager.Constrained = true;
         this.CameraManager.Center      = new Vector3(32.5f, 50.5f, 16.5f);
         this.CameraManager.SnapInterpolation();
         this.Plane.Position = this.Npc.Group.Position + new Vector3((float)(FezMath.Sign(this.Npc.State.LookingDirection) * 4) / 16f, 0.375f, 0.0f);
         this.sLetterInsert  = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/MiscActors/LetterTubeInsert");
     }
     else
     {
         this.Plane.Position         = new Vector3(20.5f, 20.75f, 23.5f);
         this.Enabled                = false;
         this.GomezService.ReadMail += new Action(this.Destroy);
     }
     this.LevelManager.LevelChanged += new Action(this.TryDestroy);
 }