public MainViewModel( IBusyStateRegistry busyStateManager, INavigationService navigationService, MvvmDialogs.IDialogService dialogService) { // This long route to the assembly name is to ensure tests also work Title = Assembly.GetExecutingAssembly().GetCustomAttributes( typeof(AssemblyProductAttribute)) .OfType <AssemblyProductAttribute>() .FirstOrDefault() .Product; BusyStateManager = busyStateManager; _navigationService = navigationService; SelectedIndexManager = _navigationService; SelectedIndexManager.SelectedIndex = (int)HamburgerNavItemsIndex.Login; DialogService = dialogService; StoryFilterCmd = new RelayCommand(OnStoryFilter, () => CanExecuteStoryFilter); ClearStoryFilterCmd = new RelayCommand(OnClearStoryFilter, () => CanExecuteStoryFilter); FullScreenCmd = new RelayCommand(OnFullScreen, () => CanExecuteFullScreenToggle); TinkerCmd = new RelayCommand(() => Tinker.Run(), () => true); ExitCmd = new RelayCommand(OnExit); MessengerInstance.Register <AuthenticatedMessage>(this, OnAuthenticated); }
public Tinker GenerateNew(DbAccount account) { var tinker = new Tinker((uint)entries.Count, Tinker.CreateNew(account.AccountId, 0x2352, 1)); InsertAsync(tinker); return(tinker); }
public async void UpdateAsync(Tinker quest, ITransaction transaction = null) { try { await DeleteAsync(quest, transaction); await InsertAsync(quest, transaction); } catch (Exception ex) { log.Error(ex); } }
protected override void HandlePacket(Client client, QuestRedeem redeem) { #if !NO_TINKER_QUESTS var quest = client.Manager.Tinker.GetQuestForAccount(client.Account.AccountId); if (!client.Player.Inventory.ValidateSlot(redeem.Object)) { client.SendPacket(new QuestRedeemResponse { Ok = false, Message = "Invalid slot." }); return; } if (redeem.Object.ObjectType != quest.Goal) { client.SendPacket(new QuestRedeemResponse { Ok = false, Message = "I HAVENT REQUESTED THAT ITEM YOU F*****G SHITCUNT." }); return; } //credits for now, just so I can test it var t1 = client.Manager.Database.UpdateCredit(client.Account, 1); client.Player.Credits++; client.Player.Inventory.QueueChange(redeem.Object.SlotId, null); var trans = client.Manager.Database.Conn.CreateTransaction(); var t2 = Inventory.TrySaveChangesAsync(trans, client.Player); var t3 = trans.ExecuteAsync(); Task.WhenAll(t1, t2, t3).ContinueWith(t => client.Player.UpdateCount++); client.SendPacket(new QuestRedeemResponse { Ok = true, Message = "" }); quest.Goal = Tinker.RandomGoal(client.Manager.Resources.GameData); quest.Tier++; client.Manager.Tinker.UpdateAsync(quest); #else client.SendPacket(new QuestRedeemResponse { Ok = false, Message = "Tinkering is disabled atm." }); #endif }
private bool UpdateList(Tinker quest, Task <bool> task, bool add) { if (!(!task.IsCanceled && task.Result)) { return(false); } using (TimedLock.Lock(listLock)) { if (add) { entries.Add(quest); } else { entries.Remove(quest); } } return(true); }
private Task <bool> DeleteAsync(Tinker quest, ITransaction transaction = null) { var trans = transaction ?? db.CreateTransaction(); trans.AddCondition(Condition.HashExists(KEY, quest.DbId)); var task = trans.HashDeleteAsync(KEY, quest.DbId) .ContinueWith(t => UpdateList(quest, t, false)); task.ContinueWith(e => log.Error(e.Exception.InnerException.ToString()), TaskContinuationOptions.OnlyOnFaulted); if (transaction == null) { trans.ExecuteAsync(); } return(task); }
private TurnManager() { // Testing schnitzel AbstractCharacter charA = new Tinker(); // AbstractCharacter charB = new Wayfarer(); AbstractCharacter charC = new Merchant(); charA.AddStarterDeck(); // charB.AddStarterDeck(); charC.AddStarterDeck(); this.AddToTurnList(charA); // this.AddToTurnList(charB); this.AddToTurnList(charC); charA.Draw(5 + charA.drawModifier); // charB.Draw(5 + charB.drawModifier); charC.Draw(5 + charC.drawModifier); charA.curAP = charA.maxAP; // charB.curAP = charB.maxAP; charC.curAP = charC.maxAP; }
public MainViewModel( BusyStateManager busyStateManager, INavigationService navigationService, MvvmDialogs.IDialogService dialogService) { Title = Assembly.GetEntryAssembly().GetName().Name; BusyStateManager = busyStateManager; _navigationService = navigationService; SelectedIndexManager = _navigationService; SelectedIndexManager.SelectedIndex = (int)HamburgerNavItemsIndex.Login; DialogService = dialogService; StoryFilterCmd = new RelayCommand(OnStoryFilter, () => CanExecuteStoryFilter); ClearStoryFilterCmd = new RelayCommand(OnClearStoryFilter, () => CanExecuteStoryFilter); FullScreenCmd = new RelayCommand(OnFullScreen, () => CanExecuteFullScreenToggle); TinkerCmd = new RelayCommand(() => Tinker.Run(), () => true); ExitCmd = new RelayCommand(OnExit); MessengerInstance.Register<AuthenticatedMessage>(this, OnAuthenticated); }
public Task <bool> InsertAsync(Tinker quest, ITransaction transaction = null) { var trans = transaction ?? db.CreateTransaction(); var buff = new byte[4 + quest.ByteLength]; Buffer.BlockCopy(BitConverter.GetBytes(quest.DbId), 0, buff, 0, 4); Buffer.BlockCopy(quest.Bytes, 0, buff, 4, quest.ByteLength); trans.AddCondition(Condition.HashNotExists(KEY, quest.DbId)); var task = trans.HashSetAsync(KEY, quest.DbId, buff) .ContinueWith(t => UpdateList(quest, t, true)); task.ContinueWith(e => log.Error(e.Exception.InnerException.ToString()), TaskContinuationOptions.OnlyOnFaulted); if (transaction == null) { trans.ExecuteAsync(); } return(task); }
public override void OnMovement(Mobile m, Point3D oldLocation) { base.OnMovement(m, oldLocation); int hours, minutes, uoDay, totalUoDays, totalMinutes; Server.Items.Clock.GetTime(m.Map, m.X, m.Y, out hours, out minutes, out totalMinutes); totalUoDays = (int)Math.Ceiling((double)totalMinutes / (60 * 24)); Math.DivRem(totalUoDays, 30, out uoDay); //if (uoDay== 1 || uoDay == 7 || uoDay == 15 || uoDay== 23) // { if (hours >= 6 && hours <= 20) { int marketplace = m_market.Count; int marketplacemob = m_marketmob.Count; if (marketplace >= marketCount && marketplacemob >= marketCount) { return; } bool validLocation = false; Map map = this.Map; switch (Utility.Random(11)) { #region fisherman case 0: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandFishEastAddon market = new MarketStandFishEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; Fisherman marketmob1 = new Fisherman(); int gx = X + 3; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion #region mercer case 1: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandMercerEastAddon market = new MarketStandMercerEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; // Tailor marketmob1 = new Tailor(); int gx = X + 3; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion #region vegetables case 2: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandVegetablesEastAddon market = new MarketStandVegetablesEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; // Farmer marketmob1 = new Farmer(); int gx = X - 2; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion #region cheese case 3: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandCheeseEastAddon market = new MarketStandCheeseEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; // Farmer marketmob1 = new Farmer(); int gx = X - 1; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion #region wine case 4: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandWineEastAddon market = new MarketStandWineEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y - 1; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; // Barkeeper marketmob1 = new Barkeeper(); int gx = X + 3; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion #region herbs case 5: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandHerbsEastAddon market = new MarketStandHerbsEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; // Herbalist marketmob1 = new Herbalist(); int gx = X + 3; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion #region mushroom case 6: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandMushroomEastAddon market = new MarketStandMushroomEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; // Herbalist marketmob1 = new Herbalist(); int gx = X + 3; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion #region fur case 7: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandFurEastAddon market = new MarketStandFurEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; // Furtrader marketmob1 = new Furtrader(); int gx = X + 3; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion #region bee case 8: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandBeeEastAddon market = new MarketStandBeeEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; // Beekeeper marketmob1 = new Beekeeper(); int gx = X + 3; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion #region copper case 9: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandCopperEastAddon market = new MarketStandCopperEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; // Blacksmith marketmob1 = new Blacksmith(); int gx = X + 3; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion #region tool case 10: { for (int i = marketplace; i < marketCount; ++i) { if (i == 0) { Point3D marketloc = this.Location; // MarketStandToolEastAddon market = new MarketStandToolEastAddon(); for (int k = 0; !validLocation && k < 10; ++k) { int ax = X; int ay = Y; int az = map.GetAverageZ(ax, ay); if (validLocation = map.CanFit(ax, ay, this.Z, 16, false, false)) { marketloc = new Point3D(ax, ay, Z); } else if (validLocation = map.CanFit(ax, ay, az, 16, false, false)) { marketloc = new Point3D(ax, ay, az); } } market.MoveToWorld(marketloc, this.Map); m_market.Add(market); } } for (int i = marketplacemob; i < marketmobCount; ++i) { if (i == 0) { Point3D marketloc6 = this.Location; // Tinker marketmob1 = new Tinker(); int gx = X + 3; int gy = Y; int gz = map.GetAverageZ(gx, gy); if (validLocation = map.CanFit(gx, gy, this.Z, 16, false, false)) { marketloc6 = new Point3D(gx, gy, Z); } else if (validLocation = map.CanFit(gx, gy, gz, 16, false, false)) { marketloc6 = new Point3D(gx, gy, gz); } marketmob1.Home = marketloc6; marketmob1.RangeHome = 0; marketmob1.MoveToWorld(marketloc6, this.Map); m_marketmob.Add(marketmob1); } } break; } #endregion } } else { foreach (Item that in m_market) { that.Delete(); } foreach (Mobile thats in m_marketmob) { thats.Delete(); } } }
public DbTinker(IDatabase db) { this.db = db; this.entries = new List <Tinker>(db.HashGetAll(KEY).Select(x => Tinker.Load(BitConverter.ToUInt32(x.Value, 0), Encoding.UTF8.GetString(x.Value, 4, ((byte[])x.Value).Length - 4)))); }
static void Demo() { var ____ = Spider.Factory; var _____ = TestTinkerStuff.tinker; var ______ = TestStatusStuff.status; System.Console.WriteLine("\n ------ Definition + Instantiation Demo ------ \n"); World world = new World(5, 5); System.Console.WriteLine("Created world"); // Statused.RegisterStatus(TestStatusTinkerStuff.status, 1); var packed = Registry.Default.Tinker.PackModMap(); Registry.Default.Tinker.SetServerMap(packed); var player.Factory = new EntityFactory<Player>(); player.Factory.AddBehavior(Attackable.DefaultPreset); player.Factory.AddBehavior(Attacking.Preset); player.Factory.AddBehavior(Displaceable.DefaultPreset); player.Factory.AddBehavior(Moving.Preset); player.Factory.AddBehavior(Pushable.Preset); player.Factory.AddBehavior(Statused.Preset); System.Console.WriteLine("Set up player.Factory"); Acting.Config playerActingConf = new Acting.Config(Algos.SimpleAlgo, null); player.Factory.AddBehavior(Acting.Preset(playerActingConf)); player.Factory.Retouch(Hopper.Core.Retouchers.Skip.EmptyAttack); // this one's for the equip demo player.Factory.Retouch(Hopper.Core.Retouchers.Equip.OnDisplace); var enemy.Factory = new EntityFactory<Entity>(); enemy.Factory.AddBehavior(Attackable.DefaultPreset); enemy.Factory.AddBehavior(Attacking.Preset); enemy.Factory.AddBehavior(Displaceable.DefaultPreset); enemy.Factory.AddBehavior(Moving.Preset); enemy.Factory.AddBehavior(Pushable.Preset); Acting.Config enemyActingConf = new Acting.Config(Algos.EnemyAlgo); enemy.Factory.AddBehavior(Acting.Preset(enemyActingConf)); var attackAction = Action.CreateBehavioral<Attacking>(); var moveAction = Action.CreateBehavioral<Moving>(); CompositeAction attackMoveAction = new CompositeAction( new Action[] { attackAction, moveAction } ); Step[] stepData = { new Step { action = null }, new Step { action = attackMoveAction, movs = Movs.Basic } }; var sequenceConfig = new Sequential.Config(stepData); enemy.Factory.AddBehavior(Sequential.Preset(sequenceConfig)); System.Console.WriteLine("Set up enemy.Factory"); Entity player = player.Factory.Instantiate(); System.Console.WriteLine("Instantiated Player"); Entity enemy = enemy.Factory.Instantiate(); System.Console.WriteLine("Instantiated Enemy"); enemy.Init(new IntVector2(1, 2), world); world.State.AddEntity(enemy); world.Grid.Reset(enemy, enemy.Pos); System.Console.WriteLine("Enemy set in world"); player.Init(new IntVector2(1, 1), world); world.State.AddPlayer(player); world.Grid.Reset(player, player.Pos); System.Console.WriteLine("Player set in world"); var playerNextAction = attackMoveAction.Copy(); playerNextAction.direction = new IntVector2(0, 1); player.Behaviors.Get<Acting>().NextAction = playerNextAction; System.Console.WriteLine("Set player action"); System.Console.WriteLine("\n ------ Modifier Demo ------ \n"); var mod = Modifier.Create(Attack.Path, new Attack { damage = 1 });//new StatModifier(Attack.Path, new Attack { damage = 1 }); var attack = player.Stats.Get(Attack.Path); System.Console.WriteLine("Attack damage:{0}", attack.damage); System.Console.WriteLine("Attack pierce:{0}", attack.pierce); System.Console.WriteLine("Adding modifier"); mod.AddSelf(player.Stats); attack = player.Stats.Get(Attack.Path); System.Console.WriteLine("Attack damage:{0}", attack.damage); System.Console.WriteLine("Attack pierce:{0}", attack.pierce); System.Console.WriteLine("Removing modifier"); mod.RemoveSelf(player.Stats); attack = player.Stats.Get(Attack.Path); System.Console.WriteLine("Attack damage:{0}", attack.damage); System.Console.WriteLine("Attack pierce:{0}", attack.pierce); var mod2 = Modifier.Create(Attack.Path, new EvHandler<StatEvent<Attack>>( (StatEvent<Attack> eve) => { System.Console.WriteLine("Called handler"); eve.file.damage *= 3; }) ); System.Console.WriteLine("Adding modifier"); mod2.AddSelf(player.Stats); attack = player.Stats.Get(Attack.Path); System.Console.WriteLine("Attack damage:{0}", attack.damage); System.Console.WriteLine("Attack pierce:{0}", attack.pierce); System.Console.WriteLine("Removing modifier"); player.Stats.RemoveChainModifier(mod2); attack = player.Stats.Get(Attack.Path); System.Console.WriteLine("Attack damage:{0}", attack.damage); System.Console.WriteLine("Attack pierce:{0}", attack.pierce); System.Console.WriteLine("\n ------ Pools Demo ------ \n"); PoolItem[] items = new[] { new PoolItem(0, 1), new PoolItem(1, 1), new PoolItem(2, 1), new PoolItem(3, 1), new PoolItem(4, 10) }; var pool = Pool.CreateNormal<Hopper.Core.Items.IItem>(); pool.AddRange("zone1/weapons", items.Take(2)); pool.AddRange("zone1/trinkets", items.Skip(2).Take(2)); pool.Add("zone1/trinkets", items[4]); var poolCopy = pool.Copy(); var it1 = pool.GetNextItem("zone1/weapons"); System.Console.WriteLine($"Item Id = {it1.id}, q = {it1.quantity}"); // var it2 = pool.GetNextItem("zone1/weapons"); // System.Console.WriteLine($"Item Id = {it2.id}, q = {it2.quantity}"); var it3 = poolCopy.GetNextItem("zone1/weapons"); System.Console.WriteLine($"Item Id = {it3.id}, q = {it3.quantity}"); var it4 = poolCopy.GetNextItem("zone1/weapons"); System.Console.WriteLine($"Item Id = {it4.id}, q = {it4.quantity}"); System.Console.WriteLine("\n ------ TargetProvider Demo ------ \n"); var pattern = new Pattern ( new Piece { pos = new IntVector2(1, 0), dir = new IntVector2(1, 0), reach = null }, new Piece { pos = new IntVector2(2, 0), dir = new IntVector2(1, 0), reach = new List<int>() } ); var weapon = TargetProvider.CreateAtk(pattern, Handlers.GeneralChain); System.Console.WriteLine($"Enemy is at {enemy.Pos}"); var atk = player.Stats.Get(Attack.Path); var targets = weapon.GetTargets(player, playerNextAction.direction, atk); foreach (var t in targets) { System.Console.WriteLine($"Entity at {t.targetEntity.Pos} has been considered a potential target"); } System.Console.WriteLine("\n ------ Inventory Demo ------ \n"); var inventory = (Inventory)player.Inventory; var slot = new SizedSlot<CircularItemContainer, Hopper.Core.Items.IItem>("stuff2", 1); inventory.AddContainer(slot); var tinker = Tinker<TinkerData>.SingleHandlered<Attacking.Event>( Attacking.Check, e => System.Console.WriteLine("Hello from tinker applied by item") ); var item = new TinkerItem(new ItemMetadata("Test_Tinker_Item"), tinker, slot); // inventory.Equip(item) -> // the starting point // item.BeEquipped(entity) -> // it's interface method // tinker.Tink(entity) -> // adds the handlers // entity.Tinkers.SetStore() // creates the tinker data inventory.Equip(item); world.Loop(); System.Console.WriteLine("Looped"); // creates excess as the size is 1 inventory.Equip(item); // inventory.DropExcess() -> // item.BeUnequipped() -> // tinker.Untink() -> entity.Tinkers.RemoveStore() // + world.CreateDroppedItem(id, pos) inventory.DropExcess(); var entities = world.Grid.GetCellAt(player.Pos).m_entities; System.Console.WriteLine($"There's {entities.Count} entities in the cell where the player is standing"); System.Console.WriteLine("\n ------ History Demo ------ \n"); var enemyUpdates = enemy.History.Updates; var playerUpdates = player.History.Updates; foreach (var updateInfo in enemyUpdates) { System.Console.WriteLine($"Enemy did {System.Enum.GetName(typeof(UpdateCode), updateInfo.updateCode)}. Position after: {updateInfo.stateAfter.pos}"); } foreach (var updateInfo in playerUpdates) { System.Console.WriteLine($"Player did {System.Enum.GetName(typeof(UpdateCode), updateInfo.updateCode)}. Position after: {updateInfo.stateAfter.pos}"); } System.Console.WriteLine("\n ------ Equip on Displace Demo ------ \n"); // we don't need the entity for the next test enemy.Die(); var playerMoveAction = moveAction.Copy(); playerMoveAction.direction = IntVector2.Down; player.Behaviors.Get<Acting>().NextAction = playerMoveAction; var slot2 = new SizedSlot<CircularItemContainer, Hopper.Core.Items.IItem>("stuff3", 1); inventory.AddContainer(slot2); var chainDefs2 = new IChainDef[0]; var tinker2 = new Tinker<TinkerData>(chainDefs2); var item2 = new TinkerItem(new ItemMetadata("Test_Tinker_Item_2"), tinker2, slot2); var droppedItem2 = world.SpawnDroppedItem(item2, player.Pos + IntVector2.Down); /* this only works because we did `player.Factory.AddRetoucher(Core.Retouchers.Equip.OnDisplace);` up top. */ System.Console.WriteLine($"Player's position before moving: {player.Pos}"); world.Loop(); System.Console.WriteLine($"Player's new position: {player.Pos}"); System.Console.WriteLine($"There's {world.Grid.GetCellAt(player.Pos).m_entities.Count} entities in the cell where the player is standing"); System.Console.WriteLine("\n ------ Tinker static reference Demo ------ \n"); var tinker3 = TestTinkerStuff.tinker; // see the definition below tinker3.Tink(player); player.Behaviors.Get<Acting>().NextAction = playerMoveAction; world.Loop(); tinker3.Untink(player); System.Console.WriteLine("\n ------ Status Demo ------ \n"); // this has to be rethought for sure var status = TestStatusStuff.status; status.TryApply( player, new StatusData(), new StatusFile { power = 1, amount = 2 } ); player.Behaviors.Get<Acting>().NextAction = playerMoveAction; world.Loop(); player.Behaviors.Get<Acting>().NextAction = playerMoveAction; world.Loop(); player.Behaviors.Get<Acting>().NextAction = playerMoveAction; world.Loop(); System.Console.WriteLine("\n ------ Spider Demo ------ \n"); player.ResetPosInGrid(new IntVector2(4, 4)); var spider = world.SpawnEntity(Spider.Factory, new IntVector2(3, 3)); world.Loop(); System.Console.WriteLine($"Tinker is applied? {BindStatuses.NoMove.IsApplied(player)}"); System.Console.WriteLine("Looped"); System.Console.WriteLine($"Player's new position: {player.Pos}"); System.Console.WriteLine($"Spider's new position: {spider.Pos}"); player.Behaviors.Get<Acting>().NextAction = attackAction; world.Loop(); System.Console.WriteLine("Looped"); System.Console.WriteLine($"Player's new position: {player.Pos}"); System.Console.WriteLine($"Spider's new position: {spider.Pos}"); player.Behaviors.Get<Displaceable>().Activate(new IntVector2(-1, -1), new Move()); world.Loop(); System.Console.WriteLine("Looped"); System.Console.WriteLine($"Player's new position: {player.Pos}"); System.Console.WriteLine($"Spider's new position: {spider.Pos}"); System.Console.WriteLine("Killing spider"); spider.Die(); world.Loop(); System.Console.WriteLine($"Tinker is applied? {BindStatuses.NoMove.IsApplied(player)}"); System.Console.WriteLine("\n ------ Input Demo ------ \n"); // we also have the possibilty to add behaviors dynamically. var Input.Factory = new BehaviorFactory<Controllable>(); var input = (Controllable)Input.Factory.Instantiate(player, new Controllable.Config { defaultAction = attackMoveAction }); player.Behaviors.Add(typeof(Controllable), input); var outputAction0 = input.ConvertVectorToAction(IntVector2.Up); System.Console.WriteLine($"Fed Up. Output: {outputAction0.direction}"); var outputAction1 = input.ConvertInputToAction(InputMapping.Special_0); System.Console.WriteLine($"Fed Special_0. Output is null?: {outputAction1 == null}"); }