public void Execute() { try { bool exec = false; InvokeMode mode = InvokeMode.im_ItSelf; switch (Action) { case EffectAction.ea_Instant: // dummy break; case EffectAction.ea_Persistent: exec = (Duration == 1); mode = InvokeMode.im_FinAction; break; case EffectAction.ea_EachTurn: exec = true; break; case EffectAction.ea_RandomTurn: exec = AuxUtils.Chance(10); break; case EffectAction.ea_LastTurn: exec = (Duration == 1); break; } if (exec) { EffectID eid = (EffectID)CLSID; if (this is MapEffect) { EffectExt ext = ((MapEffect)this).Ext; InvokeEffect(eid, null, Source, mode, EffectAction.ea_Instant, ext); } else { NWCreature creature = (NWCreature)Owner; int lid = (creature.CurrentField).LandID; bool LocusValid = (eid == EffectID.eid_Relocation) && creature.IsPlayer && creature.Effects.FindEffectByID(EffectID.eid_LocusMastery) != null && lid != GlobalVars.Land_Valhalla && lid != GlobalVars.Land_Vigrid && lid != GlobalVars.Land_Bifrost && lid != GlobalVars.Land_Nidavellir && lid != GlobalVars.Land_Niflheim && lid != GlobalVars.Land_Ocean; if (LocusValid) { EffectExt ext = new EffectExt(); ext.ReqParams = new EffectParams(EffectParams.ep_Place); GlobalVars.nwrWin.InitTarget(EffectID.eid_Relocation, null, mode, ext); } else { creature.UseEffect(eid, Source, mode, null); } } } } catch (Exception ex) { Logger.Write("Effect.execute(): " + ex.Message); } }
public void DoTurn() { try { fEmitters.UpdateEmitters(1); fEffects.Execute(); DoTurn_prepareFogs(); DoTurn_prepareScentTrails(); if (LandID == GlobalVars.Land_Wasteland) { DoTurn_eruptionWastelandVulcan(); } if (LandID == GlobalVars.Land_Muspelheim) { UniverseBuilder.Regen_Muspelheim(this); } Player player = Space.Player; if (LandID == GlobalVars.Land_Village && AuxUtils.Chance(10) && FindBuilding(player.PosX, player.PosY) == null) { int num = Features.Count; for (int i = 0; i < num; i++) { GameEntity entry = Features.GetItem(i); if (entry is Building) { ((Building)entry).Refresh(); } } } } catch (Exception ex) { Logger.Write("NWField.doTurn(): " + ex.Message); } }
public override void DoTurn() { try { base.DoTurn(); CheckTile(false); if (AuxUtils.Chance(25)) { int idx; if (Size == 1) { idx = 0; } else { idx = RandomHelper.GetRandom(Size); } IvySegment seg = (IvySegment)GetSegment(idx); if (dbIvyBranches[seg.Id].Kind == IvyBranches.ibkLeaf) { idx = GetBranchByDir(seg.EntryDir, new IvyBranches(IvyBranches.ibkBranch)); if (idx >= 0) { Directions avEntries = new Directions(dbIvyBranches[idx].Entries); avEntries.Exclude(seg.EntryDir); seg.Id = idx; seg.AvailableEntries = avEntries; seg.ImageIndex = idx; } } int cnt = 0; List <int> entries = new List <int>(); for (int dir = Directions.DtNorth; dir <= Directions.DtEast; dir++) { if (seg.AvailableEntries.Contains(dir)) { cnt++; entries.Add(dir); } } if (cnt == 0) { return; } idx = RandomHelper.GetRandom(cnt); int bdir = entries[idx]; int nx = seg.X + Directions.Data[bdir].DX; int ny = seg.Y + Directions.Data[bdir].DY; seg.AvailableEntries.Exclude(bdir); int i = FindByPos(nx, ny); if (!CurrentMap.IsBarrier(nx, ny) && i < 0) { int opposite = Directions.Data[bdir].Opposite; idx = GetBranchByDir(opposite, new IvyBranches(IvyBranches.ibkBranch, IvyBranches.ibkLeaf)); if (idx >= 0) { Directions avEntries = new Directions(dbIvyBranches[idx].Entries); avEntries.Exclude(opposite); IvySegment newSeg = (IvySegment)Add(); newSeg.X = nx; newSeg.Y = ny; newSeg.Id = idx; newSeg.EntryDir = opposite; newSeg.AvailableEntries = avEntries; newSeg.ImageIndex = idx; } } } CheckTile(true); } catch (Exception ex) { Logger.Write("IvyCreeper.doTurn(): " + ex.Message); } }
public Item Alchemy(EntityList ingredients) { Item result = null; try { Item vial = (Item)fPlayer.Items.FindByCLSID(GlobalVars.iid_Vial); if (ingredients.Count < 2) { ShowText(BaseLocale.GetStr(RS.rs_IngredientsLack)); return(null); } else { if (vial == null) { ShowText(BaseLocale.GetStr(RS.rs_NoFreeVial)); return(null); } else { //int alchemySkill = this.getSkill(TSkillID.Sk_Alchemy); EntityList ready = new EntityList(null, false); try { bool exact = false; int rec = FindAlchemyResult(ingredients, ready, ref exact); if (rec >= 0) { EntityList list; string p; if (exact) { list = ready; p = dbRecipes[rec].Potion; } else { list = ingredients; p = dbRecipes[0].Potion; } int num = list.Count; for (int i = 0; i < num; i++) { Item item = (Item)list.GetItem(i); ItemKind kind = item.Kind; if (kind == ItemKind.ik_Potion) { item.State = ItemState.is_Normal; item.CLSID = GlobalVars.iid_Vial; } else { fPlayer.DeleteItem(item); } } vial.CLSID = GlobalVars.nwrDB.FindEntryBySign(p).GUID; ShowText(BaseLocale.GetStr(RS.rs_YouProduceNewConcoction)); } else { vial.CLSID = GlobalVars.nwrDB.FindEntryBySign("Potion_Mystery").GUID; ShowText(BaseLocale.GetStr(RS.rs_MixtureBubblesHorribly)); // TODO: required to verify the conditions if (AuxUtils.Chance(5)) { ShowText(BaseLocale.GetStr(RS.rs_Boom)); fPlayer.ApplyDamage(RandomHelper.GetBoundedRnd(25, 50), DamageKind.dkPhysical, null, BaseLocale.GetStr(RS.rs_KilledByExperiment)); } } result = vial; fPlayer.Space.DoEvent(EventID.event_ItemMix, this, null, vial); } finally { ready.Dispose(); } } } } catch (Exception ex) { Logger.Write("Craft.alchemy(): " + ex.Message); } return(result); }
public override void Attack(CreatureEntity aEnemy, bool onlyRemote) { try { NWCreature self = (NWCreature)fSelf; NWCreature enemy = (NWCreature)aEnemy; int dist = MathHelper.Distance(self.Location, aEnemy.Location); bool shooting = false; int highestDamage; Item weapon = null; if (self.Entry.Flags.Contains(CreatureFlags.esMind) && (self.Entry.Flags.Contains(CreatureFlags.esUseItems))) { bool canShoot = self.CanShoot(enemy); BestWeaponSigns bw = new BestWeaponSigns(); if (canShoot) { bw.Include(BestWeaponSigns.CanShoot); } if (onlyRemote) { bw.Include(BestWeaponSigns.OnlyShoot); } highestDamage = self.CheckEquipment((float)dist, bw); weapon = self.GetItemByEquipmentKind(BodypartType.bp_RHand); ItemFlags ifs = (weapon != null) ? weapon.Flags : new ItemFlags(); shooting = (canShoot && weapon != null && (ifs.HasIntersect(ItemFlags.if_ThrowWeapon, ItemFlags.if_ShootWeapon))); } else { highestDamage = self.DamageBase; } int skDamage = 0; SkillID sk = self.GetAttackSkill(dist, ref skDamage); bool attackBySkill = (sk != SkillID.Sk_None && (skDamage > highestDamage || AuxUtils.Chance(15))); if (attackBySkill) { EffectExt ext = new EffectExt(); ext.SetParam(EffectParams.ep_Creature, aEnemy); self.UseSkill(sk, ext); } else { if (shooting) { self.ShootTo(enemy, weapon); } else { if (!onlyRemote) { if (dist == 1) { self.AttackTo(AttackKind.Melee, enemy, null, null); } else { ExtPoint next = self.GetStep(aEnemy.Location); if (!next.IsEmpty) { StepTo(next.X, next.Y); } } } } } } catch (Exception ex) { Logger.Write("BeastBrain.attack(): " + ex.Message); } }
public bool IsBreakage(bool bodyHit) { return(AuxUtils.Chance(GetBreakageChance(bodyHit))); }
// FIXME: total check & tests public void Prepare() { NWField fld = (NWField)Owner; ExtRect r = Area; r.Inflate(-1, -1); int id = (int)ID; var blRec = StaticData.dbBuildings[id]; if (ID >= BuildingID.bid_MerchantShop && ID <= BuildingID.bid_WoodsmanShop) { NWCreature merchant = (NWCreature)Holder; if (merchant == null) { Item coins = new Item(fSpace, null); coins.CLSID = GlobalVars.iid_Coin; coins.Count = (ushort)RandomHelper.GetBoundedRnd(15000, 25000); int x = RandomHelper.GetBoundedRnd(r.Left, r.Right); int y = RandomHelper.GetBoundedRnd(r.Top, r.Bottom); merchant = fld.AddCreature(x, y, GlobalVars.nwrDB.FindEntryBySign(StaticData.dbSysCreatures[(int)blRec.Owner].Sign).GUID); merchant.IsTrader = true; merchant.AddItem(coins); Holder = merchant; } else { Item coins = (Item)merchant.Items.FindByCLSID(GlobalVars.iid_Coin); if (coins != null) { coins.Count = (ushort)RandomHelper.GetBoundedRnd(15000, 25000); } } ProbabilityTable <int> data = blRec.Wares; if (((data != null) ? data.Size() : 0) > 0) { for (int y = r.Top; y <= r.Bottom; y++) { for (int x = r.Left; x <= r.Right; x++) { Item item = (Item)fld.FindItem(x, y); if (item == null) { item = new Item(fSpace, this); item.CLSID = data.GetRandomItem(); item.SetPos(x, y); item.Owner = merchant; item.GenCount(); fld.Items.Add(item, false); } else { if (AuxUtils.Chance(20)) { item.CLSID = data.GetRandomItem(); item.GenCount(); } } } } } } }