public List <Pawn> GetTargets(RollContext context) { List <Pawn> targetList = new List <Pawn>(); switch (targetType) { case TargetType.Caster: targetList.Add(context.GetCaster()); break; case TargetType.Target: Pawn target = context.GetTarget(); if (target != null) { targetList.Add(target); } break; case TargetType.Allies: targetList.AddRange(context.GetAllies()); break; case TargetType.Enemies: targetList.AddRange(context.GetEnemies()); break; case TargetType.All: targetList.AddRange(context.GetPawns()); break; } return(targetList); }
public virtual string GetShortDescription(RollContext context) { string shortDesc = ""; List <SpellComponent> componentList = BuildComponentList(context); foreach (SpellComponent component in componentList) { string compDesc = component.GetDescription(this, context); if (compDesc != null && compDesc.Length > 0) { if (requiresTarget && component.GetTargetType() == SpellComponent.TargetType.Target) { shortDesc += compDesc; shortDesc += " "; } else if (!requiresTarget) { shortDesc += compDesc; shortDesc += " "; } } } return(shortDesc.Trim()); }
public override string GetDescription(Spell spell, RollContext context) { UpdateComponentForDescription(spell, context); string desc = string.Format("Deal {0} damage", GetValue()); switch (targetType) { case TargetType.Caster: desc += " to yourself"; break; case TargetType.Allies: desc += " to all allies"; break; case TargetType.Enemies: desc += " to all enemies"; break; case TargetType.All: desc += " to everyone"; break; } desc += "."; return(desc); }
public void AddBurnAilment(Spell spell, RollContext context, List <SpellComponent> components) { Dictionary <SpellComponent.TargetType, int> damageComponentCounts = new Dictionary <SpellComponent.TargetType, int>(); if (spell.IsElement(context, Element.Fire)) { foreach (SpellComponent sc in components) { if (sc is DamageComponent) { SpellComponent.TargetType tt = sc.GetTargetType(); if (damageComponentCounts.ContainsKey(tt)) { damageComponentCounts[tt] += 1; } else { damageComponentCounts[tt] = 1; } } } } foreach (KeyValuePair <SpellComponent.TargetType, int> dcc in damageComponentCounts) { components.Add(new AilmentComponent(dcc.Key, Ailments.Burn, dcc.Value)); } }
public List <SpellComponent> BuildComponentList(RollContext context) { pattern.Match(context); List <SpellComponent> componentList = componentFactories.Select(func => func.Invoke(pattern)).ToList(); context.GetCaster().OnBuildSpellComponents.Invoke(this, context, componentList); return(componentList); }
public static async Task HandleResultAsync( [QueueTrigger("roll-result-items")] RollContext res, ILogger log) { log.LogInformation($"HandleResultAsync processed: {RealDiceConverter.Serialize(res)}"); await SendResult(res); }
public override void Match(RollContext context) { base.Match(context); optionalFulfilled = OptionalFulfilled(context); for (int i = optionalDisplayStart; i < displays.Length; i++) { displays[i].optional = !optionalFulfilled; } }
public void Cast(RollContext context) { List <SpellComponent> components = BuildComponentList(context); foreach (SpellComponent sc in components) { sc.Execute(this, context); } }
protected void UpdateComponentForDescription(Spell spell, RollContext context) { context.GetCaster().OnSpellComponentCaster.Invoke(spell, context, this); List <Pawn> targets = GetTargets(context); if (targets.Count == 1) { targets[0].OnSpellComponentTarget.Invoke(spell, context, this); } }
public void SubtractFireDamage(Spell spell, RollContext context, SpellComponent component) { if (component is DamageComponent) { if (spell.IsElement(context, Element.Fire)) { (component as DamageComponent).AddModifier(AttributeModifier.Operation.SubtractBase, 1); } } }
private bool OptionalFulfilled(RollContext context) { foreach (KeyValuePair <Element, int> elemCount in elementCountsOptional) { if (context.GetElementCount(elemCount.Key, false) < elemCount.Value) { return(false); } } return(true); }
public bool IsElement(RollContext context, Element elem) { foreach (ElementDisplay ed in GetElementDisplays(context)) { if (ed.element == elem) { return(true); } } return(false); }
public override void Execute(Spell spell, RollContext context) { context.GetCaster().OnSpellComponentCaster.Invoke(spell, context, this); int val = GetValue(); GetTargets(context).ForEach(pawn => { AilmentComponent singleTarget = new AilmentComponent(targetType, ailment, val); pawn.OnSpellComponentTarget.Invoke(spell, context, singleTarget); pawn.CmdApplyAilment(ailment, singleTarget.GetValue()); }); }
public override void Execute(Spell spell, RollContext context) { context.GetCaster().OnSpellComponentCaster.Invoke(spell, context, this); int dmg = GetValue(); GetTargets(context).ForEach(pawn => { DamageComponent singleTarget = new DamageComponent(targetType, dmg); pawn.OnSpellComponentTarget.Invoke(spell, context, singleTarget); EventBus.DamageHealEvent damageEvent = new EventBus.DamageHealEvent(spell, singleTarget, singleTarget.GetValue()); pawn.CmdDamage(damageEvent); }); }
public override void Match(RollContext context) { rollContext = context; foreach (KeyValuePair <Element, int> elemCount in elementCounts) { if (context.GetElementCount(elemCount.Key, false) < elemCount.Value) { doesMatch = false; return; } } doesMatch = true; }
public async Task RequestAsync(IActivity referenceActivity, RollRequest rollRequest) { var context = new RollContext { Id = Guid.NewGuid().ToString(), MetaData = new Dictionary <string, string> { ["RequestActivity"] = RealDiceConverter.Serialize(referenceActivity), }, Requests = new RollRequest[] { rollRequest }, }; var message = Convert.ToBase64String(Encoding.UTF8.GetBytes(RealDiceConverter.Serialize(context))); await requestQueueClient.SendMessageAsync(message); }
public override void Match(RollContext context) { base.Match(context); extensionAmount = 0; if (elementCounts.ContainsKey(extensionElement)) { extensionAmount -= elementCounts[extensionElement]; } extensionAmount += context.GetElementCount(extensionElement, false); if (extensionAmount < 0) { extensionAmount = 0; } displays[displays.Length - 1].extensionValue = extensionAmount; }
private static async Task SendResult(RollContext res) { var originalActivity = RealDiceConverter.Deserialize <Activity>(res.MetaData["RequestActivity"]); originalActivity.Value = RealDiceConverter.Serialize(res); var responseActivity = new Activity("event"); responseActivity.Value = originalActivity; responseActivity.Name = "RollResult"; responseActivity.From = new ChannelAccount("RealDiceFunctionsRollResult", "RealDiceFunctions"); var directLineSecret = Environment.GetEnvironmentVariable("DirectLineSecret"); using (DirectLineClient client = new DirectLineClient(directLineSecret)) { var conversation = await client.Conversations.StartConversationAsync(); await client.Conversations.PostActivityAsync(conversation.ConversationId, responseActivity); } }
public override string GetDescription(Spell spell, RollContext context) { return(description.Invoke(spell, context)); }
public override string GetDescription(Spell spell, RollContext context) { return(""); }
public override void Execute(Spell spell, RollContext context) { }
public override void Match(RollContext context) { doesMatch = false; rollContext = context; }
public abstract void Match(RollContext context);
public static async Task HandleRequestAsync( [QueueTrigger("roll-request-items")] RollContext req, [Queue("roll-result-items")] IAsyncCollector <RollContext> rollQueue, [Table("rollcontext")] IAsyncCollector <RollContextTableRow> rollTable, ILogger log) { log.LogInformation($"HandleRequestAsync processed: {RealDiceConverter.Serialize(req)}"); try { var iotHubServiceClient = ServiceClient.CreateFromConnectionString( Environment.GetEnvironmentVariable("IoTHubConnectionString")); var resRow = JsonConvert.DeserializeObject <RollContextTableRow>(JsonConvert.SerializeObject(req)); resRow.PartitionKey = "Bot"; resRow.RowKey = resRow.Id; await rollTable.AddAsync(resRow); // https://github.com/Azure-Samples/azure-iot-samples-csharp/blob/master/iot-hub/Quickstarts/back-end-application/BackEndApplication.cs var edgeMethodInvocation = new CloudToDeviceMethod( "Roll", TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30) ); edgeMethodInvocation.SetPayloadJson(JsonConvert.SerializeObject(new EdgeRollRequest { Id = req.Id, // XXX メッセージを受け取る。 Message = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") })); var testres = await iotHubServiceClient.GetServiceStatisticsAsync(); log.LogInformation($" GetServiceStatisticsAsync: {RealDiceConverter.Serialize(testres)}"); // XXX 複数Edgeを扱えるようになればDeviceIdは動的にバランスさせたい。 var deviceId = Environment.GetEnvironmentVariable("IoTHubRealDiceEdgeDeviceId"); var moduleId = Environment.GetEnvironmentVariable("IoTHubRealDiceEdgeModuleId"); var edgeResponse = await iotHubServiceClient.InvokeDeviceMethodAsync( deviceId, moduleId, edgeMethodInvocation ); log.LogInformation($" edgeResponse: {RealDiceConverter.Serialize(edgeResponse)}"); if (edgeResponse.Status < 300) { return; } } catch (Exception ex) { log.LogError(ex, $" Edge Request Failed: {ex.Message}"); } // Edgeへのリクエストが失敗したらFunctionsで応答するためのキューに結果を入れる。 var res = req; res.Results = req.Requests.Select(x => new RollResult { Request = x, Status = "Offline", Results = Enumerable.Range(0, (int)x.N).Select(x => (uint)randomizer.Next(1, 7)).ToArray(), }).ToList(); await rollQueue.AddAsync(res); }
public void UpdateContext() { RollContext context = battle.BuildContext(); bool anyCastable = false; for (int i = 0; i < spellButtons.Length; i++) { SpellButton b = spellButtons[i]; b.castable = b.spell.Matches(context); if (!b.castable && b.currentState != UIObj.State.Disabled) { b.currentState = UIObj.State.Disabled; } else if (b.castable && b.currentState == UIObj.State.Disabled) { b.currentState = UIObj.State.Enabled; } if (b.castable && spellButtonOwnership[i] == battle.currentTurn) { anyCastable = true; } } if (battle.currentTurn != Game.peerId || battle.rollsLeft == 0) { if (!(battle.currentTurn == Game.peerId && battle.rollsLeft == 0 && !anyCastable)) { rollButton.currentState = UIObj.State.Disabled; } foreach (DieButton db in dieButtons) { db.currentState = UIObj.State.Disabled; } } else { if (rollButton.currentState == UIObj.State.Disabled) { rollButton.currentState = UIObj.State.Enabled; } foreach (DieButton db in dieButtons) { if (db.currentState == UIObj.State.Disabled) { db.currentState = UIObj.State.Enabled; } } } if (battle.currentTurn == Game.peerId && battle.rollsLeft == 0) { //rollButton.SetText("Pass"); TODO passButton.isVisible = true; rollButton.currentState = UIObj.State.Disabled; } else { passButton.isVisible = false; } /* OLD Pass button behaviour (appears only when no castable spells) * if(battle.currentTurn == Game.peerId && battle.rollsLeft == 0 && !anyCastable) { * //rollButton.SetText("Pass"); TODO * passButton.isVisible = true; * rollButton.currentState = UIObj.State.Disabled; * } */ if (battle.log.Count > 0) { int start = Mathf.Max(0, battle.log.Count - 7); int end = battle.log.Count - 1; string text = ""; for (int i = start; i <= end; i++) { if (i > start) { text += "\n"; } text += battle.log[i]; } battleLog.SetText(text); } }
public static T SetValidityContext <T>(this T entity, RollContext value) where T : FeatureDefinitionDieRollModifier { entity.SetField("validityContext", value); return(entity); }
public bool Matches(RollContext context) { pattern.Match(context); return(pattern.Matches()); }
public abstract string GetDescription(Spell spell, RollContext context);
public abstract void Execute(Spell spell, RollContext context);
public ElementDisplay[] GetElementDisplays(RollContext context) { pattern.Match(context); return(pattern.GetElementDisplays()); }