public static IEnumerator LineSurface(Emplacement place, OptionEffect options) { Vector3i shape = options.OptionShape.shape; /// (avancée, hauteur, largeur) Vector3i above = Vectors.Up; Vector3i pos = place.ipos; Vector3i offsetSurface = new Vector3i(0, options.OptionShape.offsetSurface, 0); bool reverse = options.OptionShape.reverse != ""; float pace = options.OptionShape.pace; bool collapse_once = options.OptionShape.reverse == "once"; Block air = Block.GetBlockByName("air", false); Block blk = options.OptionBlock.block; BlockSetter setter = new BlockSetter(options.OptionBlock); /// IntLine traj = new IntLine(place.ipos, Vectors.Float.UnitX); IntLine traj = new IntLine(place.ipos, Emplacement.Truncate(place.direction, true, true)); for (int avance = 0; avance < shape.x; avance++) { Vector3i where = traj.Get(avance); Debug.Log("LineSurface " + avance.ToString()); IntLine orth = new IntLine(Vectors.ToFloat(where), Vectors.Float.UnitZ); foreach (int ligne in LR(shape.z)) { Vector3i at = orth.Get(ligne); //Debug.Log("Line Surface inner " + p.ToString()); at = Geo3D.Surface(at); // I don't need surface before orthogonal ... surface made after setter.Apply(at + above + offsetSurface); } setter.Push(); yield return(new WaitForEndOfFrame()); } }
// Start is called before the first frame update void Start() { controller = GameObject.Find("MoveTheBlockController").GetComponent <BlockSetter>(); _rb = GetComponent <Rigidbody2D>(); directionAxis = bounds.transform.localScale.y > bounds.transform.localScale.x ? Vector2.up : Vector2.right; offset = bounds.transform.localScale.y > bounds.transform.localScale.x ? transform.position.y : transform.position.x; offset -= Mathf.FloorToInt(offset); }
public override void Effect1(EntityPlayer player, Emplacement place, OptionEffect opt) { Vector3i where = place.ipos; where = where + rand.RandomRange(30, 50) * Vectors.Up; BlockSetter setter = new BlockSetter(opt.OptionBlock); Block previous = setter.options.block; setter.Apply(where); setter.Push(); }
public static IEnumerator CactusGrowth(Entity player, Emplacement place, OptionEffect options) { Vector3i where = Geo3D.Surface(place.ipos) + Vectors.Up; string[] cactuses = new String[] { "treeCactus04", "treeCactus05", "treeCactus06", "treeCactus03", "treeCactus02", "treeCactus01" }; foreach (string blk in cactuses) { BlockSetter.SetBlockAt(where, Block.GetBlockByName(blk, false), options); yield return(new WaitForSeconds(1f)); } }
public static IEnumerator TrapLine(Entity player, Emplacement place, OptionEffect options) { /// TODO: recoder ca avec rift Vector3i offsetSurface = new Vector3i(0, options.OptionShape.offsetSurface, 0); Vector3i pos = place.ipos; // size = E/W=largeur, hauteur, N/S profondeur (portee) Vector3i size = options.OptionShape.shape; Vector3 base_direction = Emplacement.Truncate(place.direction, true, true); float pace = 0.1f; // TODO pace in option Block air = Block.GetBlockByName("air", false); // The air instance could prolly be shared ... // Block blk = options.OptionBlock.block; int portee = 100; BlockSetter setter = new BlockSetter(options.OptionBlock); BlockSetter setterAir = new BlockSetter(options.OptionBlock.Copy()); setterAir.options.block = air; Vector3 posf = Vectors.ToFloat(pos + offsetSurface); // string[] random_blocks = new string[]{"trapSpikesWoodDmg0", "trapSpikesWoodDmg1", "trapSpikesWoodDmg2"}; // Block[] random_blocks = options.OptionBlock.blocks; Vector3i start = Geo3D.Surface(place.ipos); for (int k = 0; k < 10; k++) { Vector3 direction = base_direction + Vectors.Float.Randomize(GameManager.Instance.World.GetGameRandom(), 0.1f); direction.y = 0; direction = direction.normalized; // IntLine traj = new IntLine(start, direction); //east IEnumerable <Vector3i> segment = IntLine.Segment(Vectors.ToFloat(start), direction, 1, 10); // skip 0 intersecting with the previous foreach (Vector3i where in segment) { Vector3i Swhere = Geo3D.Surface(where); // randomisation : "trapSpikesWoodDmg0-2" // string rdm = random_blocks[(int) Math.Floor(GameManager.Instance.World.GetGameRandom().RandomFloat*3)]; // setter.options.block = Block.GetBlockByName(rdm, false); // Block rdm = setter.Apply(Swhere + Vectors.Up); setter.Push(); start = Swhere; yield return(new WaitForEndOfFrame()); } yield return(new WaitForSeconds(0.5f)); } }
public static IEnumerator Wave(Entity _player, Emplacement place, OptionEffect options) { /* NB: position ou ray peuvent etre ds le vide. Il faut partir une case dessous et not erase ? */ Vector3i offsetSurface = new Vector3i(0, options.OptionShape.offsetSurface, 0); Vector3i pos = place.ipos; // size = E/W=largeur, hauteur, N/S profondeur (portee) Vector3i size = options.OptionShape.shape; Vector3 direction = Emplacement.Truncate(place.direction, true, true); float pace = 0.1f; // TODO pace in option Block air = Block.GetBlockByName("air", false); // The air instance could prolly be shared ... Block blk = options.OptionBlock.block; int portee = 10; // [!] BlockSetter setter = new BlockSetter(options.OptionBlock); BlockSetter setterAir = new BlockSetter(options.OptionBlock.Copy()); setterAir.options.block = air; Vector3 posf = Vectors.ToFloat(pos + offsetSurface); for (int forward = 1; forward <= portee; forward++) { foreach (int width in LR(size.x)) { setter.Apply(Vectors.Toward(posf, direction, forward)); // avant de la vague setter.Push(); yield return(new WaitForSeconds(pace)); setter.Apply(Vectors.Toward(posf, direction, forward - 1)); setter.Apply(Vectors.Toward(posf, direction, forward - 1) + Vectors.Up); // if not exist material to speed up? setter.Push(); yield return(new WaitForSeconds(pace)); if (forward > 3) // TODO: test existing ? { setterAir.Apply(Vectors.Toward(posf, direction, forward - 1 - 2)); setterAir.Apply(Vectors.Toward(posf, direction, forward - 1 - 2) + Vectors.Up); setterAir.Push(); } } // __BUG(); // FIXME test } }
/* * * Options: * - ground (water, traps) * - recursion * - size / depth (puis avant) * - other content : Z, animal, torch, lights ... * */ public static IEnumerator Rift(EntityPlayer player, Emplacement place, OptionEffect options) { /* * Laisse des blocks tomber au dessus ? just changed erase="yes" * (longueur 1, hauteur (profonfeur), replicats) */ EntityPlayerLocal epl = player as EntityPlayerLocal; epl.cameraTransform.SendMessage("ShakeBig"); yield return(new WaitForSeconds(1f)); BlockSetter setter = new BlockSetter(options.OptionBlock); Vector3 direction = Vectors.Copy(place.direction); direction.y = 0; direction = direction.normalized; Vector3i start = Geo3D.Surface(place.ipos); for (int k = 0; k < options.OptionShape.shape.z; k++) { Vector3 kdirection = direction + Vectors.Float.Randomize(GameManager.Instance.World.GetGameRandom(), 0.2f); // IntLine traj = new IntLine(start, direction); //east IEnumerable <Vector3i> segment = IntLine.Segment(Vectors.ToFloat(start), kdirection, 0, options.OptionShape.shape.x); Vector3i prev = new Vector3i(); bool hasprev = false; foreach (Vector3i where in segment) { Vector3i Swhere = Geo3D.Surface(where); setter.Apply(Swhere); if (hasprev) { for (int creuse = 1; creuse < options.OptionShape.shape.y; creuse++) { setter.Apply(prev + creuse * Vectors.Down); } } setter.Push(); start = Swhere; yield return(new WaitForEndOfFrame()); hasprev = true; prev = Swhere; } yield return(new WaitForSeconds(1f)); } }
public IEnumerator SpawnBlock(EntityAlive ctrl, Vector3 pos) { Printer.Log(30, "MinEventActionImpactSpawn", ctrl, pos, ctrl.GetPosition()); yield return(new WaitForSeconds((float)this.dt / 1000f)); BlockSetter.Options opt = new BlockSetter.Options(); opt.avoidBlock = false; opt.avoidEntity = false; opt.elastic = 0; opt.SetBlocks(this.block); BlockSetter setter = new BlockSetter(opt); setter.OnCreation = BlockSetter.Rotate; Vector3i ipos = Vectors.ToInt(pos); Vector3i surf = Geo3D.Surface(ipos, ipos.y) + Vectors.Up; // setter.Apply(ipos); // is it pos +1 ? do we need surface ? setter.Apply(surf); setter.Push(); }
public static IEnumerator Rift(EntityPlayer player, Emplacement place, OptionEffect options) { /* * Laisse des blocks tomber au dessus ? just changed erase="yes" */ Vector3i offsetSurface = new Vector3i(0, options.OptionShape.offsetSurface, 0); EntityPlayerLocal epl = player as EntityPlayerLocal; epl.cameraTransform.SendMessage("ShakeBig"); yield return(new WaitForSeconds(1f)); // Vector3i shape = options.OptionShape.shape; /// (longueur, hauteur, largeur) BlockSetter setter = new BlockSetter(options.OptionBlock); Vector3i start = Geo3D.Surface(place.ipos); for (int k = 0; k < 3; k++) { // Vector3 direction = Vectors.Float.UnitX + Vectors.Float.Randomize(GameManager.Instance.World.GetGameRandom(), 0.1f); Vector3 direction = place.direction + Vectors.Float.Randomize(GameManager.Instance.World.GetGameRandom(), 0.1f); direction.y = 0; direction = direction.normalized; // IntLine traj = new IntLine(start, direction); //east IEnumerable <Vector3i> segment = IntLine.Segment(Vectors.ToFloat(start), direction, 1, 5); // skip 0 intersecting with the previous foreach (Vector3i where in segment) { Vector3i Swhere = Geo3D.Surface(where) + offsetSurface; setter.Apply(Swhere); setter.Apply(Swhere + Vectors.Up); setter.Apply(Swhere + 2 * Vectors.Up); setter.Push(); start = Swhere; yield return(new WaitForEndOfFrame()); } yield return(new WaitForSeconds(1f)); } }
public static IEnumerator Cave(EntityPlayer player, Emplacement place, OptionEffect options) { /// TODO: enumérer les colonnes et s'arreter à surface BlockSetter setter = new BlockSetter(options.OptionBlock); Vector3i shape = options.OptionShape.shape; Vector3i start = Geo3D.Surface(place.ipos); int depth = shape.y; Vector3 direction = Vectors.Float.UnitY; // cannot use negative, so positive and get(_k) ! IntLine colonne = new IntLine(Vectors.ToFloat(start), direction); // Debug.Log(String.Format("Cave: pos={0} start={1} dir={2} ground={3}", place.position, start, direction, ground)); for (int d = 0; d < depth; d++) { // Debug.Log(String.Format("cave {0} {1}", d, setter)); if (options.OptionShape.ground != "" && d == depth - 1) { setter.options.block = Block.GetBlockByName(options.OptionShape.ground, false); } Vector3i where = colonne.Get(-d); Vector3i dxy = new Vector3i(0, 0, 0); foreach (int p in SdtdUtils.EffectsGround.LR(shape.x)) { foreach (int q in SdtdUtils.EffectsGround.LR(shape.z)) { dxy.x = p; dxy.z = q; Printer.Log(20, "Cave Apply (d,p) =", d, p, "where, dxy=", where, dxy); setter.Apply(where + dxy); } } Printer.FLog(20, "cave Push {0} {1}", d, where); setter.Push(); } yield return(new WaitForEndOfFrame()); }
/* * public static string Get(IDictionary<string, string> dico, string key, string def) { // UTILS * if (dico.ContainsKey(key)) return dico[key]; * return def; * } */ public static IEnumerator Peak(Entity player, Emplacement place, OptionEffect options) { Vector3i offsetSurface = new Vector3i(0, options.OptionShape.offsetSurface, 0); Vector3i pos = Geo3D.Surface(place.ipos) + Vectors.Up + offsetSurface; Vector3i shape = options.OptionShape.shape; float pace = options.OptionShape.pace; Block air = Block.GetBlockByName("air", false); // The air instance could prolly be shared ... Block blk = options.OptionBlock.block; BlockSetter setter = new BlockSetter(options.OptionBlock); Printer.Log(20, "Peak (position/pos=Surface+Up):", place.ipos, pos); Printer.Log(20, " (blk/pace/shape)", options.OptionBlock.block, options.OptionShape.pace, options.OptionShape.shape); Printer.Log(20, " setter (avB/avE,elastic):", options.OptionBlock.avoidBlock, options.OptionBlock.avoidEntity, options.OptionBlock.elastic); // Start at -1 only if air below for (int h = 0; h < shape.y; h++) { foreach (int e in LR(shape.x)) { foreach (int n in LR(shape.z)) { Vector3i where = new Vector3i(pos.x + e, pos.y + h, pos.z + n); setter.Apply(where); } setter.Push(); yield return(new WaitForSeconds(pace)); } // } if (options.OptionShape.reverse == "") { yield break; } // unset if exists options.OptionBlock.block = air; options.OptionBlock.avoidBlock = false; // protected by testing blk.blockID, and preventing us from actually deleting ! setter = new BlockSetter(options.OptionBlock); // IEnumerable<int> heights = Enumerable.Range(0, shape.y-1); IEnumerable <int> heights = Enumerable.Range(0, shape.y); if (options.OptionShape.reverse.Contains('U')) { } else { heights = Enumerable.Reverse(heights); } foreach (int h in heights) // when destroyed from below, collapse => destroy top to bottom { foreach (int e in LR(shape.x)) { foreach (int n in LR(shape.z)) { Vector3i where = new Vector3i(pos.x + e, pos.y + h, pos.z + n); BlockValue existing = GameManager.Instance.World.GetBlock(where); if (existing.type == blk.blockID) // only erase the type I just inserted { setter.Apply(where); // TODO: reverse once option // yield return new WaitForSeconds(sleep); } } } if (!options.OptionShape.reverse.Contains('O')) /// not once: update progressively { setter.Push(); yield return(new WaitForSeconds(pace)); } } }