public bool SellMarketTest(Tick tick, int size) { switch (_State) { case TradeState.Start: _State = TradeState.MarketSellTrade; break; case TradeState.MarketSellTrade: Log.Notice("Market Sell"); Orders.Enter.ActiveNow.SellMarket(size); _State = TradeState.MarketSellTradeWaitFill; Log.Notice("MarketSell Trade Placed"); break; case TradeState.MarketSellTradeWaitFill: break; case TradeState.MarketSellTradeFilled: if (Position.HasPosition) { Log.Notice("Closing MarketSell Trade"); Orders.Exit.ActiveNow.GoFlat(); _State = TradeState.MarketSellTradeCloseing; } break; case TradeState.MarketSellTradeCloseing: break; case TradeState.MarketSellTradeClosed: break; } return(true); }
public override void Cancel() { switch (state) { case ShopState.JanlSelect: state = ShopState.Menu; trade = TradeState.None; break; case ShopState.GoodsSelect: if (trade == TradeState.Buy) { state = ShopState.JanlSelect; nowJanl = null; } else { state = ShopState.Menu; } break; case ShopState.ValueSelect: state = ShopState.GoodsSelect; shopValue = 1; GoodsValueChange(0); break; default: break; } ObjectActive(state); }
public Trade(string tradeName, EZInstrument tradeInstrument) { this.Name = tradeName; this.tradeInstrument = tradeInstrument; VirtualQuantity = 1; QuantityMultiplier = 1; BuySell = zBuySell.Buy; // TODO: Not sure if we want this to be initialized this.currentTradeState = TradeState.NOT_STARTED; AutoRestart = false; Throttle = 5; this.tradeActive = true; this.Metrics = null; throttleTimer = new Timer(); throttleTimer.Elapsed += throttleTimer_Elapsed; execution = new SimpleExecutionEngine(); execution.PartialFill += execution_PartialFill; execution.CompleteFill += execution_CompleteFill; // Create the TradeSteps that make up this trade. tradeSteps = new Dictionary <TradeStepType, TradeStep>(); tradeSteps[TradeStepType.PRECONDITIONS] = new TradeStep(TradeStepType.PRECONDITIONS, BooleanRuleCombination.AND); tradeSteps[TradeStepType.ENTRY] = new TradeStep(TradeStepType.ENTRY); tradeSteps[TradeStepType.EXIT] = new TradeStep(TradeStepType.EXIT); tradeSteps[TradeStepType.STOP] = new TradeStep(TradeStepType.STOP); }
public void SetOffer(long newCredit, IList <long> newItemEids) { State = TradeState.Offer; _credit = newCredit; _items.Clear(); var data = new Dictionary <string, object> { { k.characterID, owner.Id }, { k.credit, _credit }, }; if (!newItemEids.IsNullOrEmpty()) { var myContainer = owner.GetPublicContainerWithItems(); foreach (var newItemEid in newItemEids) { var item = myContainer.GetItem(newItemEid); if (item == null) { continue; } _items.Add(new TradeItem(item)); } var items = _items.ToDictionary <TradeItem, string, object>(item => "i" + item.itemEid, item => item.ToDictionary()); data.Add(k.items, items); } Message.Builder.SetCommand(Commands.TradeOffer).WithData(data).ToCharacters(owner, trader).Send(); }
/// <summary> /// Takes calculated experience and applies bonus multiplier for some conditions /// </summary> /// <param name="experience">The experience</param> /// <param name="holdsLuckyEgg"><c>True</c> if the Pokémon holds a Lucky Egg</param> /// <param name="tradingState">The trading state of the Pokémon</param> /// <param name="expPower">The state of Pass Power or O-Power</param> /// <returns>The experience with applied bonus</returns> double ApplyExperienceBonus(double experience, bool holdsLuckyEgg, TradeState tradingState, ExpPower expPower) { if (holdsLuckyEgg) // Modifier for lucky egg { experience = experience * 1.5; } // Modifier for traded Pokémon if (tradingState == TradeState.TradedNational) { experience = Math.Floor(experience * 1.5); } else if (tradingState == TradeState.TradedInternational) { experience = Math.Floor(experience * 1.7); } if (expPower != ExpPower.None) { // Modifier for Exp Point Power double expMod = ConvertExpPowerToDouble(expPower); experience = Math.Floor(experience * expMod); } return(experience); }
private void CancelPlayerItemSelect() { FrameworkCore.PlayCue(sounds.click.back); ClearStates(); tradeState = TradeState.selectTraderItem; }
public static void MoveItem() { if (column == NPC_COLUMN) { var item = npcItems[row]; npcItems.Remove(new Item(item.name, 1)); playerItems.Add(new Item(item.name, 1)); } else { var item = playerItems[row]; playerItems.Remove(new Item(item.name, 1)); npcItems.Add(new Item(item.name, 1)); } if (npc.IsTradeAcceptable(npcItems)) { tradeState = TradeState.GOOD; currentNPCWords = RandUtil.Index(PRPGame.closestNPC.personality.goodTrade); } else { tradeState = TradeState.BAD; currentNPCWords = RandUtil.Index(PRPGame.closestNPC.personality.badTrade); } CheckRow(); CheckColumn(); }
//todo: use events private void TradeSuccess() { if (ShakeDown) { Buyer.Attitude += CurrentArt.Value; CurrentComment = "I knew you would understand."; } else { Buyer.Attitude++; CurrentComment = "That's a deal!"; } Player.ArtWorks.Remove(CurrentArt); SelectionWheel.DestroySaleObject(); Player.Food += CurrentOffer.GetFoodValue(); Player.Security += CurrentOffer.GetSecurityValue(); //TODO: remove items from inventory Debug.Log($"You just sold {CurrentArt} for {CurrentOffer.AsText()}!"); CurrentTradeState = TradeState.Success; OnUpdate.Invoke(); }
public void Accept(IPlayer player) { if (player == null) throw new ArgumentNullException(nameof(player)); if (player == Owner) throw new ArgumentException("Can't accept a trade if owner == player"); if (!player.HasResources(Request)) throw new InvalidOperationException("Player should have the requested resources"); if (!Owner.HasResources(Offer)) throw new InvalidOperationException("Owner doesn't have the required resources (anymore)!"); lock (tradeLock) { if (State != TradeState.Open) throw new InvalidOperationException("Trade can no longer be accepted, because it's no longer open!"); IRawMaterial[] requested = player.TakeResources(Request); IRawMaterial[] offered = Owner.TakeResources(Offer); Owner.AddResources(requested); player.AddResources(offered); State = TradeState.Processed; } logger.Info($"Trade accepted From {Owner.Name} To {player.Name}. Offer {string.Join(", ", Offer)}, Request {string.Join(", ", Request)}"); }
/// <summary> /// Resets the trade component. /// </summary> public void Reset() { TargetId = 0; ItemCount = 0; Gold = 0; State = TradeState.Item; Items = new ItemContainerComponent(_maxTradeItemsCapacity); }
public void CantOpenTradeThatIsNotOpen(TradeState state) { var market = new Market(); var trade = new Mock<ITrade>(); trade.Setup(t => t.State).Returns(state); Assert.Throws<ArgumentException>(() => market.OpenTrade(trade.Object)); }
public TradeComponent() { this.TargetId = 0; State = TradeState.Item; Items = new ItemContainerComponent(TradeSystem.MaxTrade); ItemCount = 0; Gold = 0; }
public FixedPriceOrder( string id, DateTime createTime, OrderState state, ClientExtensions?clientExtensions, OrderType type, string instrument, TimeInForce timeInForce, DateTime?gtdTime, OrderPositionFill positionFill, OrderTriggerCondition triggerCondition, TakeProfitDetails?takeProfitOnFill, StopLossDetails?stopLossOnFill, GuaranteedStopLossDetails?guaranteedStopLossOnFill, TrailingStopLossDetails?trailingStopLossOnFill, ClientExtensions?tradeClientExtensions, string?fillingTransactionID, DateTime?filledTime, string?tradeOpenedID, string?tradeReducedID, ImmutableList <string>?tradeClosedIDs, string?cancellingTransactionID, DateTime?cancelledTime, string?replacesOrderID, string?replacedByOrderID, decimal units, decimal price, TradeState tradeState) : base( id, createTime, state, clientExtensions, type, instrument, timeInForce, gtdTime, positionFill, triggerCondition, takeProfitOnFill, stopLossOnFill, guaranteedStopLossOnFill, trailingStopLossOnFill, tradeClientExtensions, fillingTransactionID, filledTime, tradeOpenedID, tradeReducedID, tradeClosedIDs, cancellingTransactionID, cancelledTime, replacesOrderID, replacedByOrderID) { Units = units; Price = price; TradeState = tradeState; }
private void TradeFailure() { Debug.Log($"{CurrentArt} not sold. Last offer: {CurrentOffer.AsText()}"); SelectionWheel.DestroySaleObject(); CurrentTradeState = TradeState.Collapse; OnUpdate.Invoke(); }
protected void ManageTradeByTrailingATR() { double risk = EMA(ATR(MMAtrPeriod), MMAtrEMAPeriod)[0] * MMAtrMultiplier; if (IsLong) { switch (_tradeState) { case TradeState.InitialStop: // switch to breakeven if possible and start trailing if (Close[0] > _positionPrice + (TickSize * ProfitTicksBeforeBreakeven)) { _lossLevel = _positionPrice + (TickSize * BreakevenTicks); StopLoss.Set(_lossLevel); // SetStopLoss("long", CalculationMode.Price, _lossLevel, true); _tradeState = TradeState.Trailing; } break; case TradeState.Trailing: if (Low[0] - risk > _lossLevel) { _lossLevel = Low[0] - risk; StopLoss.Set(_lossLevel); // SetStopLoss("long", CalculationMode.Price, _lossLevel, true); } break; } } else if (IsShort) { switch (_tradeState) { case TradeState.InitialStop: // switch to breakeven if possible and start trailing if (Close[0] < _positionPrice - (TickSize * ProfitTicksBeforeBreakeven)) { _lossLevel = _positionPrice - (TickSize * BreakevenTicks); StopLoss.Set(_lossLevel); // SetStopLoss("short", CalculationMode.Price, _lossLevel, true); _tradeState = TradeState.Trailing; } break; case TradeState.Trailing: if (High[0] + risk < _lossLevel) { _lossLevel = High[0] + risk; StopLoss.Set(_lossLevel); // SetStopLoss("short", CalculationMode.Price, _lossLevel, true); } break; } } StopLoss.Set(_lossLevel); }
public Trade(int id, DateTime tradeTime, ICounterparty counterparty, ITransferable itemTraded, int quantityTraded, double itemPrice, TradeState state) { Id = id; TradeTime = tradeTime; Counterparty = counterparty; ItemTraded = itemTraded; QuantityTraded = quantityTraded; ItemPrice = itemPrice; State = state; }
public void Cancel() { lock (tradeLock) { if (State != TradeState.Open) throw new InvalidOperationException("Can't cancel a trade if it's not open"); State = TradeState.Canceled; } logger.Info("Trade canceled"); }
/// <summary> /// Calculates experience points gained from a battle in third generation (RSE, FrLg, ...) /// </summary> /// <param name="baseExperience">The base experience of the defeated Pokémon</param> /// <param name="enemyLevel">The level of the defeated Pokémon</param> /// <param name="participatedPokemon">The number of Pokémon that participated in the battle and did not fainted</param> /// <param name="isWild"><c>True</c> if the enemy is a wild Pokémon</param> /// <param name="isTraded"><c>True</c> if the Trainer ID of the Pokémon for which the experience is calculated does not match the Trainer ID of the player</param> /// <param name="holdsLuckyEgg"><c>True</c> if the Pokémon holds a Lucky Egg</param> /// <param name="expShareCount">The amount of Pokémon in the team that are holding an Exp.Share</param> /// <param name="holdsExpShare"><c>True</c> if the Pokémon holds an Exp.Share</param> /// <returns>The calculated experience points for the Pokémon</returns> public int CalculateExperienceForThirdGen(ushort baseExperience, byte enemyLevel, byte participatedPokemon, bool isWild, bool isTraded, bool holdsLuckyEgg, byte expShareCount, bool holdsExpShare) { double enemyCount = CalculateEnemyCount(participatedPokemon, expShareCount, holdsExpShare); // Unlike the first two generations these steps don't have to be rounded down double experience = (baseExperience * enemyLevel) / (enemyCount * 7.0); TradeState tradeState = isTraded ? TradeState.TradedNational : TradeState.Original; experience = ApplyExperienceBonus(experience, isWild, holdsLuckyEgg, tradeState); return(Convert.ToInt32(Math.Floor(experience))); }
private void StartShakeDown() { CurrentOffer = new CommodityGroup(); CurrentComment = $"That's nice! How about you give it to me and I will make sure nothing bad happens to you."; Patience = 3; CurrentTradeState = TradeState.Negotiating; OnUpdate.Invoke(); }
public ShopManager(MenuManager m) : base(m) { myObjct = GameObject.Find("Menu").transform.Find("Shop").gameObject; state = ShopState.Menu; trade = TradeState.None; ObjectDicSet(); ShopListGet(); shopListParent = ShopObject[ShopState.GoodsPanel].transform.GetChild(0).GetChild(0).GetChild(0).gameObject; itemButtonPrefab = Resources.Load <GameObject>("Prefabs/ItemButton"); itemButtons = new List <GameObject>(); goodsPanel = ShopObject[ShopState.GoodsPanel].transform.Find("GoodsPanel"); sort = myObjct.transform.GetChild(0).GetChild(2).Find("SortPanel").GetComponent <ItemListSort>(); }
private void NextTest() { if (_Current < Tests.LastTest) { _Current = _Current + 1; _State = TradeState.Start; if (_Current == Tests.LastTest) { Log.Notice("Tests Completed"); } Log.NoticeFormat("Starting test {0}", _Current); } }
public FixedPriceOrderTransaction( string id, DateTime time, int?userID, string accountID, string?batchID, string?requestID, TransactionType type, ClientExtensions?clientExtensions, string?replacesOrderID, string?cancellingTransactionID, TimeInForce timeInForce, DateTime?gtdTime, string instrument, decimal units, OrderPositionFill positionFill, TakeProfitDetails?takeProfitOnFill, StopLossDetails?stopLossOnFill, TrailingStopLossDetails?trailingStopLossOnFill, GuaranteedStopLossDetails?guaranteedStopLossOnFill, ClientExtensions?tradeClientExtensions, decimal price, TradeState tradeState, FixedPriceOrderReason reason) : base( id, time, userID, accountID, batchID, requestID, type, clientExtensions, replacesOrderID, cancellingTransactionID, timeInForce, gtdTime, instrument, units, positionFill, takeProfitOnFill, stopLossOnFill, trailingStopLossOnFill, guaranteedStopLossOnFill, tradeClientExtensions) { Price = price; TradeState = tradeState; Reason = reason; }
private void ManageTrade() { if (IsLong) { switch (_tradeState) { case TradeState.InitialStop: // switch to breakeven if possible and start trailing if (Close[0] > Position.AvgPrice + (TickSize * _mmProfitTicksBeforeBreakeven)) { _lossLevel = Position.AvgPrice + TickSize * _mmBreakevenTicks; SetStopLoss(CalculationMode.Price, _lossLevel); _tradeState = TradeState.Trailing; } break; case TradeState.Trailing: if (Close[0] - TickSize * _mmTrailTicks > _lossLevel) { _lossLevel = Close[0] - TickSize * _mmTrailTicks; SetStopLoss(CalculationMode.Price, _lossLevel); } break; } } else if (IsShort) { switch (_tradeState) { case TradeState.InitialStop: // switch to breakeven if possible and start trailing if (Close[0] < Position.AvgPrice - (TickSize * _mmProfitTicksBeforeBreakeven)) { _lossLevel = Position.AvgPrice - TickSize * _mmBreakevenTicks; SetStopLoss(CalculationMode.Price, _lossLevel); _tradeState = TradeState.Trailing; } break; case TradeState.Trailing: if (Close[0] + TickSize * _mmTrailTicks < _lossLevel) { _lossLevel = Close[0] + TickSize * _mmTrailTicks; SetStopLoss(CalculationMode.Price, _lossLevel); } break; } } DrawLossLevel(); }
/// <summary> /// Calculates experience points gained from a battle in second generation (Gold, Silver, Crystal) /// </summary> /// <param name="baseExperience">The base experience of the defeated Pokémon</param> /// <param name="enemyLevel">The level of the defeated Pokémon</param> /// <param name="participatedPokemon">The number of Pokémon that participated in the battle and did not fainted</param> /// <param name="isWild"><c>True</c> if the enemy is a wild Pokémon</param> /// <param name="isTraded"><c>True</c> if the Trainer ID of the Pokémon for which the experience is calculated does not match the Trainer ID of the player</param> /// <param name="holdsLuckyEgg"><c>True</c> if the Pokémon holds a Lucky Egg</param> /// <param name="expShareCount">The amount of Pokémon in the team that are holding an Exp.Share</param> /// <param name="holdsExpShare"><c>True</c> if the Pokémon holds an Exp.Share</param> /// <returns>The calculated experience points for the Pokémon</returns> public int CalculateExperienceForSecondGen(ushort baseExperience, byte enemyLevel, byte participatedPokemon, bool isWild, bool isTraded, bool holdsLuckyEgg, byte expShareCount, bool holdsExpShare) { double experience = CalculateEnemyCount(participatedPokemon, expShareCount, holdsExpShare); // Every step must be rounded down experience = Math.Floor(baseExperience / experience); experience = Math.Floor(experience * enemyLevel); experience = Math.Floor(experience / 7.0); TradeState tradeState = isTraded ? TradeState.TradedNational : TradeState.Original; experience = ApplyExperienceBonus(experience, isWild, holdsLuckyEgg, tradeState); return(Convert.ToInt32(experience)); }
private void UpdatePopup(GameTime gameTime) { if (tradeState != TradeState.popup) { return; } //check if we're the top menu. if (Owner.menus[Owner.menus.Count - 1] == this) { tradeState = TradeState.intro; } }
public static bool IsStateDeletable(TradeState state) { switch (state) { case TradeState.Listed: case TradeState.Offered: case TradeState.PendingOffer: case TradeState.Denied: return(true); default: return(false); } }
/// <summary> /// 用于GridView控件中的订单支付状态显示值 /// </summary> /// <param name="ts"></param> /// <returns></returns> protected string tradeState(TradeState ts) { switch (ts) { case TradeState.SUCCESS: return("支付成功"); case TradeState.REFUND: return("转入退款"); case TradeState.NOTPAY: return("未支付"); case TradeState.CLOSED: return("已关闭"); case TradeState.REVOKED: return("已撤销(刷卡支付)"); case TradeState.USERPAYING: return("用户支付中"); case TradeState.PAYERROR: return("支付失败(其他原因,如银行返回失败)"); case TradeState.CASHPAID: return("已付现金"); case TradeState.CASHNOTPAID: return("未付现金"); case TradeState.AP_WAIT_BUYER_PAY: return("等待买家付款"); case TradeState.AP_TRADE_SUCCESS: return("交易成功"); case TradeState.AP_TRADE_FINISHED: return("交易结束"); case TradeState.AP_TRADE_PENDING: return("等待卖家收款"); case TradeState.AP_TRADE_CLOSED: return("交易未支付已关闭"); default: return("未知状态"); } }
private void CustomerChance() { if (CustomerToday()) { OnNewCustomer.Invoke(); } else { var r = GetRaider(); if (r) { RaidController.StartFight(r); } CurrentTradeState = TradeState.NoCustomer; } }
public static void Setup(Player _player, NPC _npc) { npcItems.Clear(); playerItems.Clear(); tradeState = TradeState.NONE; npc = _npc; player = _player; foreach (var item in npc.inventory) { npcItems.Add(item); } foreach (var item in player.inventory) { playerItems.Add(item); } currentNPCWords = npc.personality.GetIdleChat(); }
int CalculateExperienceYield(int generation, ushort baseExperience, byte enemyLevel, byte ownLevel, byte participated, bool isWild, TradeState tradeState, bool holdsLuckyEgg, byte expShareCount, bool holdsExpShare, ExpPower expPower) { bool isTraded = tradeState == TradeState.TradedNational; switch (generation) { case 2: return _experienceCalculator.CalculateExperienceForSecondGen(baseExperience, enemyLevel, participated, isWild, isTraded, holdsLuckyEgg, expShareCount, holdsExpShare); case 3: return _experienceCalculator.CalculateExperienceForThirdGen(baseExperience, enemyLevel, participated, isWild, isTraded, holdsLuckyEgg, expShareCount, holdsExpShare); case 4: return _experienceCalculator.CalculateExperienceForFourthGen(baseExperience, enemyLevel, participated, isWild, tradeState, holdsLuckyEgg, expShareCount, holdsExpShare); case 5: return _experienceCalculator.CalculateExperienceForFifthGen(baseExperience, enemyLevel, ownLevel, participated, isWild, tradeState, holdsLuckyEgg, expShareCount, holdsExpShare, expPower); } return 0; }
public TradeSummary( string id, string instrument, decimal price, DateTime openTime, TradeState state, decimal initialUnits, decimal initialMarginRequired, decimal currentUnits, decimal realizedPL, decimal unrealizedPL, decimal marginUsed, decimal?averageClosePrice, ImmutableList <string> closingTransactionIDs, decimal financing, decimal dividendAdjustment, DateTime closeTime, ClientExtensions clientExtensions, string?takeProfitOrderID, string?stopLossOrderID, string?guaranteedStopLossOrderID, string?trailingStopLossOrderID) { Id = id; Instrument = instrument; Price = price; OpenTime = openTime; State = state; InitialUnits = initialUnits; InitialMarginRequired = initialMarginRequired; CurrentUnits = currentUnits; RealizedPL = realizedPL; UnrealizedPL = unrealizedPL; MarginUsed = marginUsed; AverageClosePrice = averageClosePrice; ClosingTransactionIDs = closingTransactionIDs; Financing = financing; DividendAdjustment = dividendAdjustment; CloseTime = closeTime; ClientExtensions = clientExtensions; TakeProfitOrderID = takeProfitOrderID; StopLossOrderID = stopLossOrderID; GuaranteedStopLossOrderID = guaranteedStopLossOrderID; TrailingStopLossOrderID = trailingStopLossOrderID; }
public static TradeState ParseTraseState(string state) { TradeState tradeState = TradeState.NONE; if (string.IsNullOrEmpty(state)) { return(tradeState); } if (!string.IsNullOrEmpty(state)) { switch (state.Trim().ToUpper()) { case "SUCCESS": tradeState = TradeState.SUCCESS; break; case "REFUND": tradeState = TradeState.REFUND; break; case "NOTPAY": tradeState = TradeState.NOTPAY; break; case "CLOSED": tradeState = TradeState.CLOSED; break; case "REVOKED": tradeState = TradeState.REVOKED; break; case "USERPAYING": tradeState = TradeState.USERPAYING; break; case "PAYERROR": tradeState = TradeState.PAYERROR; break; } } return(tradeState); }
/// <summary> /// Calculates experience points gained from a battle in fifth generation (BW, B2W2, ...) /// </summary> /// <param name="baseExperience">The base experience of the defeated Pokémon</param> /// <param name="enemyLevel">The level of the defeated Pokémon</param> /// <param name="ownLevel">The level of the Pokémon for which the Exp are calculated</param> /// <param name="participatedPokemon">The number of Pokémon that participated in the battle and did not fainted</param> /// <param name="isWild"><c>True</c> if the enemy is a wild Pokémon</param> /// <param name="tradingState">The state of the Pokémon (Owned by Player, traded, traded from another country)</param> /// <param name="holdsLuckyEgg"><c>True</c> if the Pokémon holds a Lucky Egg</param> /// <param name="expShareCount">The amount of Pokémon in the team that are holding an Exp.Share</param> /// <param name="holdsExpShare"><c>True</c> if the Pokémon holds an Exp.Share</param> /// <param name="ExpPower">The state of Pass Power (5th Gen C-Gear feature)</param> /// <returns>The calculated experience points for the Pokémon</returns> public int CalculateExperienceForFifthGen(ushort baseExperience, byte enemyLevel, byte ownLevel, byte participatedPokemon, bool isWild, TradeState tradingState, bool holdsLuckyEgg, byte expShareCount, bool holdsExpShare, ExpPower expPower) { double a = (enemyLevel * 2.0) + 10; double c = enemyLevel + ownLevel + 10.0; double enemyCount = CalculateEnemyCount(participatedPokemon, expShareCount, holdsExpShare); double b = (baseExperience * enemyLevel) / (5.0 * enemyCount); // Trainer Bonus must be applied here if (!isWild) b = b * 1.5; // Adapted formula from http://www.serebii.net/games/exp.shtml double experience = Math.Floor(Math.Floor(Math.Sqrt(a) * (a * a)) * Math.Floor(b) / Math.Floor(Math.Sqrt(c) * (c * c))) + 1.0; // Apply all other experience bonuses experience = ApplyExperienceBonus(experience, holdsLuckyEgg, tradingState, expPower); return Convert.ToInt32(Math.Floor(experience)); }
private void LookForTrade() { if (_indi.Signal == 0) { return; } double risk = TickSize * _mmInitialSL; if (_indi.Signal == 1) { _lossLevel = Close[0] - risk; _entry = EnterLong(ComputeQty(risk)); } else if (_indi.Signal == -1) { _lossLevel = Close[0] + risk; _entry = EnterShort(ComputeQty(risk)); } _tradeState = TradeState.InitialStop; }
private void StartTrade() { int artAptitude = 0; if (CurrentArt.Colors.Contains(WantedColor)) { artAptitude++; } if (CurrentArt.Properties.Contains(WantedProperty)) { artAptitude++; } CurrentOffer = Buyer.Inventory.GetResourcesOfValue(Random.Range(CurrentArt.Value / 5, CurrentArt.Value + Patience)); switch (artAptitude) { case 0: Patience = Buyer.Attitude / 2; CurrentComment = $"That's not really what I wanted. I can give you <b>{CurrentOffer.AsText()}</b>"; break; case 1: Patience = Buyer.Attitude; CurrentComment = $"Alright. I can give you <b>{CurrentOffer.AsText()}</b> for that"; break; case 2: Patience = Buyer.Attitude + 5; CurrentComment = $"That's perfect! I will give you <b>{CurrentOffer.AsText()}</b>"; break; } CurrentTradeState = TradeState.Negotiating; OnUpdate.Invoke(); }
private async Task SetStateAsync(TradeState state, string prepend = "") { if (State != state) { LastState = State; State = state; } var content = new StringBuilder(); if (!string.IsNullOrWhiteSpace(prepend)) { content.AppendLine(prepend); } switch (state) { case TradeState.Menu: content.Append(WriteTradeMenu()); break; case TradeState.Inventory: if (!CurrentId.HasValue) { throw new Exception("Cannot read the inventory of an empty primary ID"); } content.Append(WriteInventory(GetAccount(CurrentId.Value))); break; case TradeState.Success: content.AppendLine("> ✅ **Success!**\n> The trade has successfully gone through."); content.Append(WriteTradeResult()); Host.AddToVar(Stats.TimesTraded); Participant.AddToVar(Stats.TimesTraded); break; } await UpdateMessageAsync(content.ToString()); }
private void ManageTrade() { if (IsLong) { switch (_tradeState) { case TradeState.InitialStop: // switch to breakeven if possible and start trailing if (Close[0] > Position.AvgPrice + (TickSize*_mmProfitTicksBeforeBreakeven)) { _lossLevel = Position.AvgPrice + TickSize * _mmBreakevenTicks; SetStopLoss(CalculationMode.Price, _lossLevel); _tradeState = TradeState.Trailing; } break; case TradeState.Trailing: if (Close[0] - TickSize*_mmTrailTicks > _lossLevel) { _lossLevel = Close[0] - TickSize* _mmTrailTicks; SetStopLoss(CalculationMode.Price, _lossLevel); } break; } } else if (IsShort) { switch (_tradeState) { case TradeState.InitialStop: // switch to breakeven if possible and start trailing if (Close[0] < Position.AvgPrice - (TickSize * _mmProfitTicksBeforeBreakeven)) { _lossLevel = Position.AvgPrice - TickSize * _mmBreakevenTicks; SetStopLoss(CalculationMode.Price, _lossLevel); _tradeState = TradeState.Trailing; } break; case TradeState.Trailing: if (Close[0] + TickSize * _mmTrailTicks < _lossLevel) { _lossLevel = Close[0] + TickSize * _mmTrailTicks; SetStopLoss(CalculationMode.Price, _lossLevel); } break; } } DrawLossLevel(); }
public int ShouldCalculateExperienceForGen4(ushort baseExperience, byte enemyLevel, byte participatedPokemon, bool isWild, TradeState tradeState, bool holdsLuckyEgg, byte expShareCount, bool holdsExpShare) { return _service.CalculateExperienceForFourthGen(baseExperience, enemyLevel, participatedPokemon, isWild, tradeState, holdsLuckyEgg, expShareCount, holdsExpShare); }
/// <summary> /// Calculates experience points gained from a battle in fourth generation (DPP, HgSs, ...) /// </summary> /// <param name="baseExperience">The base experience of the defeated Pokémon</param> /// <param name="enemyLevel">The level of the defeated Pokémon</param> /// <param name="participatedPokemon">The number of Pokémon that participated in the battle and did not fainted</param> /// <param name="isWild"><c>True</c> if the enemy is a wild Pokémon</param> /// <param name="tradingState">The state of the Pokémon (Owned by Player, traded, traded from another country)</param> /// <param name="holdsLuckyEgg"><c>True</c> if the Pokémon holds a Lucky Egg</param> /// <param name="expShareCount">The amount of Pokémon in the team that are holding an Exp.Share</param> /// <param name="holdsExpShare"><c>True</c> if the Pokémon holds an Exp.Share</param> /// <returns>The calculated experience points for the Pokémon</returns> public int CalculateExperienceForFourthGen(ushort baseExperience, byte enemyLevel, byte participatedPokemon, bool isWild, TradeState tradingState, bool holdsLuckyEgg, byte expShareCount, bool holdsExpShare) { double enemyCount = CalculateEnemyCount(participatedPokemon, expShareCount, holdsExpShare); // Unlike the first two generations these steps don't have to be rounded down double experience = (baseExperience * enemyLevel) / (enemyCount * 7.0); experience = ApplyExperienceBonus(experience, isWild, holdsLuckyEgg, tradingState); return Convert.ToInt32(Math.Floor(experience)); }
private void LookForTrade() { if (_indi.Signal == 0) return; double risk = TickSize*_mmInitialSL; if (_indi.Signal == 1) { _lossLevel = Close[0] - risk; _entry = EnterLong(ComputeQty(risk)); } else if (_indi.Signal == -1) { _lossLevel = Close[0] + risk; _entry = EnterShort(ComputeQty(risk)); } _tradeState = TradeState.InitialStop; }
public int ShouldCalculateExperienceForGen6(ushort baseExperience, byte enemyLevel, bool isWild, TradeState tradeState, bool holdsLuckyEgg, ExpPower expPowerState, bool hasAffection, bool couldEvolve, bool expShareActive, bool isActive) { return _service.CalculateExperienceForSixthGen(baseExperience, enemyLevel, isWild, tradeState, holdsLuckyEgg, expPowerState, hasAffection, couldEvolve, expShareActive, isActive); }
/// <summary> /// Takes calculated experience and applies bonus multiplier for some conditions /// </summary> /// <param name="experience">The experience</param> /// <param name="isWild"><c>True</c> if the enemy is a wild Pokémon</param> /// <param name="holdsLuckyEgg"><c>True</c> if the Pokémon holds a Lucky Egg</param> /// <param name="tradingState">The trading state of the Pokémon</param> /// <param name="expPower">The state of Pass Power or O-Power</param> /// <param name="hasAffection"><c>True</c> if the Pokémon has 2 or more hearts in Pokémon-Amie</param> /// <param name="couldEvolve"><c>True</c> if the Pokémon is at a level where it could have evolved but didn't</param> /// <returns>The experience with applied bonus</returns> double ApplyExperienceBonus(double experience, bool isWild, bool holdsLuckyEgg, TradeState tradingState, ExpPower expPower, bool hasAffection, bool couldEvolve) { experience = ApplyExperienceBonus(experience, holdsLuckyEgg, tradingState, expPower); //experience = Math.Round(experience, MidpointRounding.AwayFromZero); if (!isWild) // Modifier for Trainer experience = experience * 1.5; if (hasAffection) // Modifier for Pokémon-Amie experience = experience * 1.2; if (couldEvolve) // Modifier for Pokémon that could have evolved experience = experience * 1.2; return experience; }
/// <summary> /// Takes calculated experience and applies bonus multiplier for some conditions /// </summary> /// <param name="experience">The experience</param> /// <param name="holdsLuckyEgg"><c>True</c> if the Pokémon holds a Lucky Egg</param> /// <param name="tradingState">The trading state of the Pokémon</param> /// <param name="expPower">The state of Pass Power or O-Power</param> /// <returns>The experience with applied bonus</returns> double ApplyExperienceBonus(double experience, bool holdsLuckyEgg, TradeState tradingState, ExpPower expPower) { if (holdsLuckyEgg) // Modifier for lucky egg experience = experience * 1.5; // Modifier for traded Pokémon if (tradingState == TradeState.TradedNational) experience = Math.Floor(experience * 1.5); else if (tradingState == TradeState.TradedInternational) experience = Math.Floor(experience * 1.7); if (expPower != ExpPower.None) { // Modifier for Exp Point Power double expMod = ConvertExpPowerToDouble(expPower); experience = Math.Floor(experience * expMod); } return experience; }
/// <summary> /// Takes calculated experience and applies bonus multiplier for some conditions /// </summary> /// <param name="experience">The experience</param> /// <param name="isWild"><c>True</c> if the enemy is a wild Pokémon</param> /// <param name="holdsLuckyEgg"><c>True</c> if the Pokémon holds a Lucky Egg</param> /// <param name="tradingState">The trading state of the Pokémon</param> /// <returns>The experience with applied bonus</returns> double ApplyExperienceBonus(double experience, bool isWild, bool holdsLuckyEgg, TradeState tradingState) { // These must be rounded down for all generations if (!isWild) // Modifier for Trainer Battle experience = Math.Floor(experience * 1.5); if (holdsLuckyEgg) // Modifier for lucky egg experience = Math.Floor(experience * 1.5); // Modifier for traded Pokémon if (tradingState == TradeState.TradedNational) experience = Math.Floor(experience * 1.5); else if (tradingState == TradeState.TradedInternational) experience = Math.Floor(experience * 1.7); return experience; }
/// <summary> /// Calculates experience points gained from a battle in sixth generation (XY, OrAs, ...) /// </summary> /// <param name="baseExperience">The base experience of the defeated Pokémon</param> /// <param name="enemyLevel">The level of the defeated Pokémon</param> /// <param name="isWild"><c>True</c> if the enemy is a wild Pokémon</param> /// <param name="tradingState">The state of the Pokémon (Owned by Player, traded, traded from another country)</param> /// <param name="holdsLuckyEgg"><c>True</c> if the Pokémon holds a Lucky Egg</param> /// <param name="expPower">The state of Pass Power (5th Gen C-Gear feature)</param> /// <param name="couldEvolve"><c>True</c> if the Pokémon is at a level where it could have evolved but didn't</param> /// <param name="hasAffection"><c>True</c> when the Pokémon has 2 or more hearts in PokémonAmie</param> /// <param name="expShareActive"><c>True</c> when Exp.Share is active</param> /// <param name="isActive"><c>False</c> when the Pokémon was not in the battle and Exp.Share is active, else <c>true</c></param> /// <returns>The calculated experience points for the Pokémon</returns> public int CalculateExperienceForSixthGen(ushort baseExperience, byte enemyLevel, bool isWild, TradeState tradingState, bool holdsLuckyEgg, ExpPower expPower, bool hasAffection, bool couldEvolve, bool expShareActive, bool isActive) { double a = isWild ? 1.0 : 1.5; double b = holdsLuckyEgg ? 1.5 : 1.0; double c = hasAffection ? 1.2 : 1.0; double d = ConvertExpPowerToDouble(expPower); double e = couldEvolve ? 1.2 : 1.0; double f = 1.0; if (tradingState == TradeState.TradedNational) f = 1.5; else if (tradingState == TradeState.TradedInternational) f = 1.7; double g = isActive ? 1.0 : 2.0; //double h = (baseExperience * enemyLevel * a * b * c * d * e * f) / (7.0 * g); //return Convert.ToInt32(Math.Round(h, MidpointRounding.AwayFromZero)); //double decimalPart = experience - Math.Truncate(experience); //if (decimalPart == 0.5) // return Convert.ToInt32(Math.Floor(experience)); //return Convert.ToInt32(Math.Floor(h)); //return Convert.ToInt32(Math.Round(h, MidpointRounding.AwayFromZero)); double enemyCount = isActive ? 1.0 : 2.0; double experience = Math.Floor((baseExperience * enemyLevel) / (enemyCount * 7.0)); if (tradingState != TradeState.Original) experience = Math.Floor(experience * f); if (holdsLuckyEgg) experience = Math.Floor(experience * b); if (!isWild) experience = Math.Floor(experience * a); if (d != 1.0) experience = Math.Floor(experience * d); if (hasAffection) experience = Math.Floor(experience * c); if (couldEvolve) experience = Math.Floor(experience * e); //experience = ApplyExperienceBonus(experience, isWild, holdsLuckyEgg, tradingState, expPower, hasAffection, couldEvolve); //if (!isWild) // experience = Math.Floor(experience + (experience * 0.5)); //double multi = f * b * c * e * d; //experience = experience * multi; //if (tradingState == TradeState.TradedNational) // experience = Math.Floor(experience * 1.5); //else if (tradingState == TradeState.TradedInternational) // experience = experience * 1.7; //experience = experience * b; //experience = experience * c; //experience = experience * e; //experience = experience * d; return Convert.ToInt32(Math.Floor(experience)); //double decimalPart = experience - Math.Truncate(experience); //if (decimalPart == 0.5) // return Convert.ToInt32(Math.Floor(experience)); //return Convert.ToInt32(Math.Round(experience, MidpointRounding.AwayFromZero)); }
protected void LookForEntry() { if (_macd.MacdUp[0] == 0 && Rising(_rsi) && Rising(_macd.Avg)) { _tradeState = TradeState.InitialStop; _lossLevel = Low[0] - TickSize * _mmInitialSL; _positionPrice = Close[0]; PositionPrice.Set(_positionPrice); StopLoss.Set(_lossLevel); SetSignal(1, "going long"); return; } if (_macd.MacdDn[0] == 0 && Falling(_rsi) && Falling(_macd.Avg)) { _tradeState = TradeState.InitialStop; _lossLevel = High[0] + TickSize * _mmInitialSL; _positionPrice = Close[0]; PositionPrice.Set(_positionPrice); StopLoss.Set(_lossLevel); SetSignal(-1, "going short"); return; } }