private void ExitCombat(Player player, NpcInstance npc, int attackType) { playerState.ExitCombat(player); playerState.ClearAttackTime(player, npc); StopAttackAnimation(player, attackType); }
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); } }
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); } }
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)); }
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); }
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))); }
/// <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)); }
public static NpcRespawn Create(NpcInstance npc, Player player) { return(new NpcRespawn { NpcServerId = npc.Id, PlayerId = player.Id, }); }
private bool OnNpcAfflictDamage( Player player, NpcInstance npc, TimeSpan totalTime, TimeSpan deltaTime) { return(false); }
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); } }
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); } }
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); } }
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); }
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. }
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); }
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); }
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); }
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 }); }
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); }
public NpcInstance CreateNpcInstance() { var id = GetNextId(npcInstances.Entities); var npc = new NpcInstance() { Id = id }; Add(npc); return(npc); }
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)); } }
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 }); }
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)); }
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]); }
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); } } }
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() }); }
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); }
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); } }
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); }
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); }