public IEnumerable <T> Create(int level) { // modify the level randomly int walkedLevel = Rng.WalkLevel(level).Clamp(1, 100); // choose up to it (best of two tries) int choiceValue = Math.Max(Rng.IntInclusive(walkedLevel), Rng.IntInclusive(walkedLevel)); IDrop <T> dropped = null; // count through to find the last one at least the random level foreach (DropChoice choice in Choices) { if (choiceValue >= choice.Odds) { dropped = choice.Drop; } } // drop it if we have one if (dropped != null) { // if the choice was less than the max, then bump up the subsequent level a bit to compensate int bonus = (walkedLevel - choiceValue) / 4; level = Math.Max(Game.MaxDepth, level + bonus); foreach (var item in dropped.Create(level)) { yield return(item); } } }
public IEnumerable <T> Create(int level) { // modify the level randomly float choiceValue = Rng.WalkLevel(level).Clamp(1, 100); IDrop <T> dropped = null; // count through to find the last one at least the random level foreach (DropChoice choice in Choices) { if (choiceValue >= choice.Odds) { dropped = choice.Drop; } } // drop it if we have one if (dropped != null) { foreach (var item in dropped.Create(level)) { yield return(item); } } }
public IEnumerable <T> Create(int level) { // use the actual total in case the data adds up to more than 100 float totalOdds = Math.Max(TotalOdds, Choices.Sum((choice) => choice.Odds)); float choiceValue = Rng.Float(TotalOdds); IDrop <T> dropped = null; // count through to find the chosen one foreach (DropChoice choice in Choices) { choiceValue -= choice.Odds; if (choiceValue <= 0) { dropped = choice.Drop; break; } } // drop it if we have one if (dropped != null) { foreach (var item in dropped.Create(level)) { yield return(item); } } }
public StoreType(Content content, string name, int depth, IDrop <Item> drop) : base(content) { mName = name; mDepth = depth; mDrop = drop; }
// Update is called once per frame void Update() { if (dropped_item != null) { IDrop d = dropped_item.GetComponent <IDrop>(); sprite_renderer.sprite = d.GetIcon(); } }
public static T CreateOne <T>(this IDrop <T> drop, int level) { foreach (T item in drop.Create(level)) { return(item); } return(default(T)); }
public RepeatDrop(NotNull <Roller> repeat, IDrop <T> drop) { if (drop == null) { throw new ArgumentNullException("drop"); } mRepeat = repeat; mDrop = drop; }
public async void OnDragCompleted(IDrop target) { if (target == CurrentDropBox) { onswap = false; } if (TargetType != target.GetType()) { return; } Constants.CurrentCategoryOrder.Remove(int.Parse(this.ClassId)); Constants.CurrentCategoryOrder.Insert(target.position, int.Parse(this.ClassId)); if (target.DraggableChildren.Count > 0 && onswap) { target.DraggableChildren[0].OnDragCompleted(CurrentDropBox); CurrentDropBox.OnDraggableDropped(target.DraggableChildren[0]); target.DraggableChildren[0].CurrentDropBox = CurrentDropBox; onswap = false; } CurrentTarget = target; CurrentDropBox = target; this.Scale = 1; this.Opacity = 1; FontSize = 10; var view = target as View; if (view != null) { var bounds = view.Bounds; await this.LayoutTo(bounds, 0, Easing.CubicIn); CurrentBounds = bounds; //System.Diagnostics.Debug.WriteLine("{0} current bounds: {1}", Text, CurrentBounds); } Status = DragState.Completed; TapEnabled = false; if (DraggedCommand != null && DraggedCommand.CanExecute(new string[] { ((DropBox)target).Date.ToString("D"), WorkoutId.ToString() })) { DraggedCommand.Execute(new string[] { ((DropBox)target).Date.ToString("d"), WorkoutId.ToString() }); } }
public void SetColor(IDrop drop) { switch (drop.Type) { case DropType.Heal: _resText.color = _green; break; case DropType.Energy: _resText.color = _yellow; break; case DropType.None: _resText.color = Color.clear; break; } }
public static void Load(string filePath, DropMacroCollection <Item> dropMacros, Content content) { var parser = new ItemDropParser(content); foreach (PropertyBag storeProperty in PropertyBag.FromFile(filePath)) { int depth = storeProperty.GetOrDefault("depth", 0); // parse the drops PropertyBag dropProp = storeProperty["drops"]; IDrop <Item> drop = parser.ParseMacro(dropProp, dropMacros); content.Stores.Add(new StoreType(content, storeProperty.Name, depth, drop)); } Console.WriteLine("Loaded " + content.Stores.Count + " stores"); }
/// <summary> /// Loads the collection of <see cref="IDrop"/> macros from the /// given file. /// </summary> /// <param name="dirPath">Path to a directory with <see cref="PropertyFile"> /// PropertyFiles</see> containing IDrop macros.</param> /// <returns>The collection of macros.</returns> public static DropMacroCollection <T> LoadDrops <T>(string dirPath, DropParser <T> parser) { DropMacroCollection <T> collection = new DropMacroCollection <T>(); // load them foreach (string filePath in Directory.GetFiles(dirPath, "*.txt")) { foreach (PropertyBag macroProp in PropertyBag.FromFile(filePath)) { IDrop <T> drop = parser.ParseMacro(macroProp, collection); collection.Add(macroProp.Name, drop); } } Console.WriteLine("Loaded " + collection.Count + " drop macros"); return(collection); }
bool MatchNearby(IDrag child, out IDrop container) { var view = child as View; container = null; if (child.TargetType == null || DroppableChildren.Count == 0) { return(false); } //find all possible targets var targetCandidates = DroppableChildren.FindAll((t) => { var v = t as View; bool near = v.Bounds.IntersectsWith(view.Bounds); return(t.GetType() == child.TargetType && near && t.DropEnabled); }); if (targetCandidates.Count == 0) { return(false); } // find the match which *contains* the draggable foreach (var target in targetCandidates) { container = target as IDrop; var targetView = target as View; if (targetView.Bounds.Contains(view.Bounds.Center)) { return(true); } } // otherwise return the first one that intersects it container = targetCandidates[0] as IDrop; return(true); }
protected void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Enemy") && collision.IsTouching(damageCol)) { health = collision.GetComponent <IDamageable <float> >(); iInvulnerable = collision.GetComponent <IInvulnerable>(); if (health == null && iInvulnerable != null) { Reject(); } if (health != null && iInvulnerable != null) { TryDoDamage(damage, health, beamType, iInvulnerable); Instantiate(impactPrefab, transform.position, Quaternion.identity, null); if (!rejected) { NoPlasmaOnTrigger?.Invoke(); } else { Reject(); } } } else if ((collision.IsTouching(floorCol) && collision.tag == "Suelo")) { FloorCollision(); } else if (collision.CompareTag("EnemyBeam")) { IDrop iDrop = collision.GetComponent <IDrop>(); if (iDrop != null) { FloorCollision(); } } }
public void Add(IDrop <T> drop, float odds) { mChoices.Add(new DropChoice(drop, odds)); }
public void SetFeatures(IDrop<string> drop) { mFeatures = drop; }
private IDrop <T> Parse(PropertyBag property, DropMacroCollection <T> macros, bool defining, out float odds) { // default odds = 0; // check for a repeat string[] parts = property.Name.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Roller repeat = null; bool hasOdds = false; if (parts.Length > 1) { // repeat (may return null) repeat = Roller.Parse(parts[0]); // odds, formatted like (12%) string oddsString = parts[parts.Length - 1]; if ((oddsString.Length > 3) && (oddsString[0] == '(') && (oddsString[oddsString.Length - 2] == '%') && (oddsString[oddsString.Length - 1] == ')')) { hasOdds = Single.TryParse(oddsString.Substring(1, oddsString.Length - 3), out odds); } // bob: hack. also allow no percent sign for "choose by level" odds, formatted like (12) if (!hasOdds && (oddsString.Length > 2) && (oddsString[0] == '(') && (oddsString[oddsString.Length - 1] == ')')) { hasOdds = Single.TryParse(oddsString.Substring(1, oddsString.Length - 2), out odds); } } int start = (repeat != null) ? 1 : 0; int count = parts.Length - start - (hasOdds ? 1 : 0); // put the remaining item type back together string text = String.Join(" ", parts, start, count); // see what the underlying type is IDrop <T> drop = null; if (defining || (text == "any of") || (text == "drops")) { var allDrop = new AllDrop <T>(); // recurse into the children foreach (PropertyBag child in property) { float childOdds = 0; IDrop <T> childDrop = Parse(child, macros, out childOdds); allDrop.Add(childDrop, childOdds); } drop = allDrop; } else if ((text == "one of") || (text == "drops one")) { var chooseDrop = new ChooseDrop <T>(); // recurse into the children foreach (PropertyBag child in property) { float childOdds = 0; IDrop <T> childDrop = Parse(child, macros, out childOdds); chooseDrop.Add(childDrop, childOdds); } chooseDrop.FixOdds(); drop = chooseDrop; } else if (text == "one from level") { var chooseDrop = new ChooseByLevelDrop <T>(); // recurse into the children foreach (PropertyBag child in property) { float childOdds = 0; IDrop <T> childDrop = Parse(child, macros, out childOdds); chooseDrop.Add(childDrop, childOdds); } drop = chooseDrop; } else if (text == "one up to level") { var chooseDrop = new ChooseUpToLevelDrop <T>(); // recurse into the children foreach (PropertyBag child in property) { float childOdds = 0; IDrop <T> childDrop = Parse(child, macros, out childOdds); chooseDrop.Add(childDrop, childOdds); } drop = chooseDrop; } else if (text == "one near level") { var chooseDrop = new ChooseNearLevelDrop <T>(); // recurse into the children foreach (PropertyBag child in property) { float childOdds = 0; IDrop <T> childDrop = Parse(child, macros, out childOdds); chooseDrop.Add(childDrop, childOdds); } drop = chooseDrop; } else if ((macros != null) && (macros.ContainsKey(text))) { // use the macro's drop (note: not cloned because drops are immutable) drop = macros[text]; } else { drop = ParseDrop(text); if (drop == null) { Console.WriteLine("Could not parse drop \"" + text + "\"."); } } // wrap it in a repeater if (repeat != null) { drop = new RepeatDrop <T>(repeat, drop); } return(drop); }
private static Race LoadRace(PropertyBag raceProp, DropMacroCollection <Item> dropMacros, Content content, out int depth, out int rarity) { Character character = new Character('*', TermColor.Purple); PropertyBag art; if (raceProp.TryGetValue("art", out art)) { //### bob: old style color and glyph combined character = Character.Parse(art.Value); } else { // separate glyph and color character = new Character( Character.ParseGlyph(raceProp["glyph"].Value), TermColors.FromName(raceProp["color"].Value)); } // depth depth = raceProp["depth"].ToInt32(); // speed int speed = raceProp.GetOrDefault("speed", 0) + Energy.NormalSpeed; // health Roller health = Roller.Parse(raceProp["health"].Value); // rarity rarity = raceProp.GetOrDefault("rarity", 1); // create the race Race race = new Race(content, raceProp.Name, depth, character, speed, health); // attacks PropertyBag attacks; if (raceProp.TryGetValue("attacks", out attacks)) { foreach (PropertyBag attackProp in attacks) { string[] attackParts = attackProp.Value.Split(' '); // create the attack Roller damage = Roller.Parse(attackParts[0]); FlagCollection flags = new FlagCollection(); Element element = Element.Anima; // add the flags or element for (int i = 1; i < attackParts.Length; i++) { try { // see if the part is an element element = (Element)Enum.Parse(typeof(Element), attackParts[i], true); } catch (ArgumentException) { // must be a flag flags.Add(attackParts[i]); } } //### bob: need to support different effect types Attack attack = new Attack(damage, 0, 1.0f, element, attackProp.Name, EffectType.Hit, flags); race.Attacks.Add(attack); } } // moves PropertyBag moves; if (raceProp.TryGetValue("moves", out moves)) { foreach (PropertyBag moveProp in moves) { string moveName = moveProp.Name; // if an explicit move field is provided, then the prop name is not the name of the move itself PropertyBag explicitMove; if (moveProp.TryGetValue("move", out explicitMove)) { moveName = explicitMove.Value; } // parse the specific move info MoveInfo info = ParseMove(moveProp); Move move; // construct the move switch (moveName) { case "haste self": move = new HasteSelfMove(); break; case "ball self": move = new BallSelfMove(); break; case "cone": move = new ElementConeMove(); break; case "breathe": move = new BreatheMove(); break; case "bolt": move = new BoltMove(); break; case "message": move = new MessageMove(); break; case "breed": move = new BreedMove(); break; default: throw new Exception("Unknown move \"" + moveName + "\"."); } move.BindInfo(info); race.Moves.Add(move); } } // flags foreach (PropertyBag childProp in raceProp) { if (childProp.Name.StartsWith("+ ")) { string flag = childProp.Name.Substring(2).Trim(); // handle the flags switch (flag) { case "groups": race.SetGroupSize(GroupSize.Group); break; case "packs": race.SetGroupSize(GroupSize.Pack); break; case "swarms": race.SetGroupSize(GroupSize.Swarm); break; case "hordes": race.SetGroupSize(GroupSize.Horde); break; case "very-bright": race.SetLightRadius(2); break; case "bright": race.SetLightRadius(1); break; case "glows": race.SetLightRadius(0); break; case "unmoving": race.SetPursue(Pursue.Unmoving); break; case "slightly-erratic": race.SetPursue(Pursue.SlightlyErratically); break; case "erratic": race.SetPursue(Pursue.Erratically); break; case "very-erratic": race.SetPursue(Pursue.VeryErratically); break; case "unique": race.SetFlag(RaceFlags.Unique); break; case "boss": race.SetFlag(RaceFlags.Boss); break; case "opens-doors": race.SetFlag(RaceFlags.OpensDoors); break; default: Console.WriteLine("Unknown flag \"{0}\"", flag); break; } } } // resists PropertyBag resists; if (raceProp.TryGetValue("resists", out resists)) { ParseResists(resists.Value, race); } // drops PropertyBag drops; if (raceProp.TryGetValue("drops", out drops)) { var parser = new ItemDropParser(content); IDrop <Item> drop = parser.ParseDefinition(drops, dropMacros); race.SetDrop(drop); } // description PropertyBag description; if (raceProp.TryGetValue("description", out description)) { race.SetDescription(description.Value); } // groups PropertyBag groups; if (raceProp.TryGetValue("groups", out groups)) { race.SetGroups(groups.Value.Split(' ')); } return(race); }
public static void RemoveDrop(IDrop drop) => Drops.Remove(drop);
public static void AddDrop(IDrop drop) => Drops.Add(drop);
//### bob: these methods exist only to be called by the data loading code to set up a race instead // of passing in a pile of constructor parameters. this is kind of gross since it means // races technically are mutable. replace these with a RaceInfo constructor parameter instead? #region Initializers public void SetDrop(IDrop <Item> drop) { mDrop = drop; }
public DropChoice(IDrop <T> drop, float odds) { Drop = drop; Odds = odds; }
public void Init(IDrop drop) => _drop = drop;
static Drop() { LogicServer.Instance.UpdateManager.InitStaticImpl(typeof(Drop), typeof(DropDefaultImpl), o => { mImpl = (IDrop)o; }); }