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;
    }
 public void mod(CommandInterrupt modable)
 {
     if (modable == null)
     {
         return;
     }
     mod(this, modable);
 }
    public override IModable copyDeep()
    {
        var result = new CommandInterrupt();

        result.Keywords = Modable.copyDeep(Keywords);
        result.Keyword  = Modable.copyDeep(Keyword);

        return(result);
    }
    public override void mod(IModable modable)
    {
        CommandInterrupt modCommand = modable as CommandInterrupt;

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

        mod(modCommand);
    }
 private void mod(CommandInterrupt original, CommandInterrupt mod)
 {
     Keywords = Modable.mod(original.Keywords, mod.Keywords);
     Keyword  = Modable.mod(original.Keyword, mod.Keyword);
 }
示例#6
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();
    }