/// <summary> /// Modifies a World Variable by name. You can set, add, multiply or subtract the value. /// </summary> /// <param name='modifier'>Modifier.</param> /// <param name='sourceTrans'>Source trans. Optional - this will output in the debug message if the World Variable is not found.</param> public static void ModifyPlayerStat(WorldVariableModifier modifier, Transform sourceTrans = null) { var statName = modifier._statName; if (!InGamePlayerStats.ContainsKey(statName)) { LevelSettings.LogIfNew( string.Format( "Transform '{0}' tried to modify a World Variable called '{1}', which was not found in this scene.", sourceTrans == null ? LevelSettings.EmptyValue : sourceTrans.name, statName)); return; } var stat = InGamePlayerStats[statName]; switch (modifier._varTypeToUse) { case VariableType._integer: case VariableType._float: stat.ModifyVariable(modifier); break; default: LevelSettings.LogIfNew("Write code for varType: " + modifier._varTypeToUse.ToString()); break; } }
/*! \cond PRIVATE */ public void ModifyVariable(WorldVariableModifier mod) { switch (mod._varTypeToUse) { case WorldVariableTracker.VariableType._integer: var modVal = mod._modValueIntAmt.Value; switch (mod._modValueIntAmt.curModMode) { case KillerVariable.ModMode.Add: AddToIntValue(modVal); break; case KillerVariable.ModMode.Set: SetIntValueIfAllowed(modVal); AddToIntValue(0); // need to trigger game over if G.O. value reached break; case KillerVariable.ModMode.Sub: AddToIntValue(-modVal); break; case KillerVariable.ModMode.Mult: MultiplyByIntValue(modVal); break; default: LevelSettings.LogIfNew("Add code for modMode: " + mod._modValueIntAmt.curModMode.ToString()); break; } break; case WorldVariableTracker.VariableType._float: var modFloatVal = mod._modValueFloatAmt.Value; switch (mod._modValueFloatAmt.curModMode) { case KillerVariable.ModMode.Add: AddToFloatValue(modFloatVal); break; case KillerVariable.ModMode.Set: SetFloatValueIfAllowed(modFloatVal); AddToFloatValue(0f); break; case KillerVariable.ModMode.Sub: AddToFloatValue(-modFloatVal); break; case KillerVariable.ModMode.Mult: MultiplyByFloatValue(modFloatVal); break; default: LevelSettings.LogIfNew("Add code for modMode: " + mod._modValueIntAmt.curModMode.ToString()); break; } break; default: LevelSettings.LogIfNew("Add code for varType: " + mod._varTypeToUse.ToString()); break; } }
private void ValidateWorldVariableModifier(WorldVariableModifier mod) { if (WorldVariableTracker.IsBlankVariableName(mod._statName)) { LevelSettings.LogIfNew( string.Format( "Killable '{0}' specifies a World Variable Modifier with no World Variable name. Please delete and re-add.", Trans.name)); } else if (!WorldVariableTracker.VariableExistsInScene(mod._statName)) { LevelSettings.LogIfNew( string.Format( "Killable '{0}' specifies a World Variable Modifier with World Variable '{1}', which doesn't exist in the scene.", Trans.name, mod._statName)); } else { switch (mod._varTypeToUse) { case WorldVariableTracker.VariableType._integer: if (mod._modValueIntAmt.variableSource == LevelSettings.VariableSource.Variable) { if (!WorldVariableTracker.VariableExistsInScene(mod._modValueIntAmt.worldVariableName)) { if (LevelSettings.IllegalVariableNames.Contains(mod._modValueIntAmt.worldVariableName)) { LevelSettings.LogIfNew( string.Format( "Killable '{0}' wants to modify World Variable '{1}' using the value of an unspecified World Variable. Please specify one.", Trans.name, mod._statName)); } else { LevelSettings.LogIfNew( string.Format( "Killable '{0}' wants to modify World Variable '{1}' using the value of World Variable '{2}', but the latter is not in the Scene.", Trans.name, mod._statName, mod._modValueIntAmt.worldVariableName)); } } } break; case WorldVariableTracker.VariableType._float: break; default: LevelSettings.LogIfNew("Add code for varType: " + mod._varTypeToUse.ToString()); break; } } }
/*! \endcond */ /// <summary> /// Modifies a World Variable by name. You can set, add, multiply or subtract the value. /// </summary> /// <param name='modifier'>Modifier.</param> /// <param name='sourceTrans'>Source trans. Optional - this will output in the debug message if the World Variable is not found.</param> public static void ModifyPlayerStat(WorldVariableModifier modifier, Transform sourceTrans = null) { var statName = modifier._statName; if (!InGamePlayerStats.ContainsKey(statName)) { LevelSettings.LogIfNew( string.Format( "Transform '{0}' tried to modify a World Variable called '{1}', which was not found in this scene.", sourceTrans == null ? LevelSettings.EmptyValue : sourceTrans.name, statName)); return; } var stat = InGamePlayerStats[statName]; switch (modifier._varTypeToUse) { case VariableType._integer: case VariableType._float: stat.ModifyVariable(modifier); break; default: LevelSettings.LogIfNew("Write code for varType: " + modifier._varTypeToUse.ToString()); break; } }