public Instruction.Result ReceiveInstruction(Instruction instr) { Instruction.Result result = Instruction.Result.ERROR; switch (instr.type) { case Instruction.Type.MOVE: if (Movable) { result = Move(instr.oriVal); } break; case Instruction.Type.SKILL: if (Holder) { result = HoldOrEase(); } else if (Packer) { result = Pack(); } else if (Unpacker) { result = Unpack(); } break; default: break; } Debug.Log(result); return(result); }
public Instruction.Result Unpack() { // if (!Unpacker) return Instruction.Result.ERROR; Instruction.Result result = Instruction.Result.ERROR; if (container is GridContainer) { GridContainer target = null; GridContainer from = (GridContainer)container; result = from.QueryAdjacentContainer(antOri, ref target); if (result == Instruction.Result.SUCCEED) { if (!target.Compatible(this)) { return(Instruction.Result.INCOMPATIBLE); } result = from.TryUnpack(this); if (result == Instruction.Result.SUCCEED) { from.Release(this); target.Contain(this); target.HoleCheck(); from.TargetCheck(); } } } return(result); }
public Instruction.Result Move(Orientation oriVal) { if (type == Type.Ant && antOri != oriVal) { return(Instruction.Result.INVALID_ANT_MOVE); } Instruction.Result result = Instruction.Result.ERROR; if (container is GridContainer) { GridContainer target = null; GridContainer from = (GridContainer)container; result = from.QueryAdjacentContainer(oriVal, ref target); if (result == Instruction.Result.SUCCEED) { if (!target.Compatible(this)) { return(Instruction.Result.INCOMPATIBLE); } from.Release(this); target.Contain(this); target.HoleCheck(); } } return(result); }
public Instruction.Result QueryAdjacentContainer(Orientation oriVal, ref GridContainer container) { if (!initialized) { return(Instruction.Result.ERROR); } Instruction.Result result = Instruction.Result.ERROR; Vector2 target; switch (oriVal) { case Orientation.UP: target = Location + new Vector2(0, 1); break; case Orientation.DOWN: target = Location + new Vector2(0, -1); break; case Orientation.LEFT: target = Location + new Vector2(-1, 0); break; case Orientation.RIGHT: target = Location + new Vector2(1, 0); break; default: return(Instruction.Result.ERROR); } result = Manager.QueryContainer(target, ref container); return(result); }
public Instruction.Result Pack() { // if (!Packer) return Instruction.Result.ERROR; Instruction.Result result = Instruction.Result.ERROR; if (container is GridContainer) { GridContainer target = null; GridContainer from = (GridContainer)container; result = from.QueryAdjacentContainer(antOri, ref target); if (result == Instruction.Result.SUCCEED) { result = target.TryPack(this); if (result == Instruction.Result.SUCCEED) { from.Release(this); target.Contain(this); target.HoleCheck(); } } } return(result); }
public Instruction.Result HoldOrEase() { // if (!Holder) return Instruction.Result.ERROR; Instruction.Result result = Instruction.Result.ERROR; if (Holding) { if (container is GridContainer) { List <Packet> toEase = new List <Packet>(); var recv = ((GridContainer)container); foreach (var packet in packets) { toEase.Add(packet); } foreach (var packet in toEase) { Release(packet); recv.Contain(packet); } recv.TargetCheck(); result = Instruction.Result.SUCCEED; } } else { if (container is GridContainer) { result = ((GridContainer)container).TryHold(this); } } if (result == Instruction.Result.SUCCEED) { dirty = true; } return(result); }