Ejemplo n.º 1
0
    public override void execute(Data data)
    {
        int duration = Duration;

        if (ToTime >= 0)
        {
            duration = GameManager.Instance.timeSecondsTils(ToTime);
        }

        int timeTilMidnight = GameManager.Instance.timeSecondsTils(0, false);

        if (OmitInterrupts == false && duration >= timeTilMidnight)
        {
            CommandsCollection commands            = new CommandsCollection();
            CommandTimePass    timePassTilMidnight = new CommandTimePass(timeTilMidnight, ActivityID, true); //Interrupts have to be omitted otherwise there will be an infinite loop
            commands.Add(timePassTilMidnight);
            CommandInterrupt dayStartInterrupt = new CommandInterrupt("dayStart");
            commands.Add(dayStartInterrupt);
            if (duration > timeTilMidnight)
            {
                CommandTimePass timePassAfterMidnight = new CommandTimePass(duration - timeTilMidnight, ActivityID); //Interrupts have to b performed because we don't check for possible further dayStart-intterupts here
                commands.Add(timePassAfterMidnight);
            }


            commands.execute();
        }
        else
        {
            GameManager.Instance.timePass(duration, ActivityID);
        }


        return;
    }
Ejemplo n.º 2
0
 public void mod(CommandTimePass modable)
 {
     if (modable == null)
     {
         return;
     }
     mod(this, modable);
 }
Ejemplo n.º 3
0
    public override IModable copyDeep()
    {
        var result = new CommandTimePass();

        result.ActivityID = Modable.copyDeep(ActivityID);
        result.Duration   = Modable.copyDeep(Duration);
        result.ToTime     = Modable.copyDeep(ToTime);
        return(result);
    }
Ejemplo n.º 4
0
    public override void mod(IModable modable)
    {
        CommandTimePass modCommand = modable as CommandTimePass;

        if (modCommand == null)
        {
            Debug.LogError("Type mismatch");
            return;
        }

        mod(modCommand);
    }
Ejemplo n.º 5
0
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        Command result;

        JObject jo = JObject.Load(reader);

        if (!Enum.TryParse((string)jo["Type"], out Command.Type commandType))
        {
            Debug.LogError($"CommandType {jo["Type"]} not recognized in {jo}");
            return(new CommandNone());
        }

        switch (commandType)
        {
        case (Command.Type.Break):
            result = new CommandBreak();
            break;

        case (Command.Type.Call):
            result = new CommandCall();
            break;

        case (Command.Type.Conditional):
            result = new CommandConditional();
            break;

        case (Command.Type.Consume):
            result = new CommandConsume();
            break;

        case (Command.Type.Continue):
            result = new CommandContinue();
            break;

        case (Command.Type.Debug):
            result = new CommandDebug();
            break;

        case (Command.Type.Dialog):
            result = new CommandDialog();
            break;

        case (Command.Type.Dialogue):
            result = new CommandDialogue();
            break;

        case (Command.Type.Event):
            result = new CommandEvent();
            break;

        case (Command.Type.EventEnd):
            result = new CommandEventEnd();
            break;

        case (Command.Type.Flush):
            result = new CommandFlush();
            break;

        case (Command.Type.GotoLocation):
            result = new CommandGotoLocation();
            break;

        case (Command.Type.Interrupt):
            result = new CommandInterrupt();
            break;

        case (Command.Type.ItemAdd):
            result = new CommandItemAdd();
            break;

        case (Command.Type.ItemRemove):
            result = new CommandItemRemove();
            break;

        case (Command.Type.NoteAdd):
            result = new CommandNoteAdd();
            break;

        case (Command.Type.NoteRemove):
            result = new CommandNoteRemove();
            break;

        case (Command.Type.Outfit):
            result = new CommandOutfit();
            break;

        case (Command.Type.OutfitManage):
            result = new CommandOutfitManage();
            break;

        case (Command.Type.Pause):
            result = new CommandPause();
            break;

        case (Command.Type.Services):
            result = new CommandServices();
            break;

        case (Command.Type.Set):
            result = new CommandSet();
            break;

        case (Command.Type.Shop):
            result = new CommandShop();
            break;

        case (Command.Type.Sleep):
            result = new CommandSleep();
            break;

        case (Command.Type.TimePass):
            result = new CommandTimePass();
            break;

        case (Command.Type.None):
        default:
            result = new CommandNone();
            break;
        }

        serializer.Populate(jo.CreateReader(), result);

        return(result);

        /*if (reader.TokenType == JsonToken.Null)
         *  return new CText();
         *
         * if (reader.TokenType == JsonToken.StartObject)
         * {
         *  //https://stackoverflow.com/questions/35586987/json-net-custom-serialization-with-jsonconverter-how-to-get-the-default-beha
         *  existingValue = existingValue ?? serializer.ContractResolver.ResolveContract(objectType).DefaultCreator();
         *  serializer.Populate(reader, existingValue);
         *  return existingValue;
         * }
         *
         * if (reader.TokenType == JsonToken.String)
         *  return new CText((string)reader.Value);
         *
         */
        //throw new JsonSerializationException();
    }
Ejemplo n.º 6
0
 private void mod(CommandTimePass original, CommandTimePass mod)
 {
     ActivityID = Modable.mod(original.ActivityID, mod.ActivityID);
     Duration   = Modable.mod(original.Duration, mod.Duration);
     ToTime     = Modable.mod(original.ToTime, mod.ToTime);
 }