From 47f4742566120bb7688d36b3458a57c2f247d06d Mon Sep 17 00:00:00 2001 From: cgars Date: Mon, 25 Jan 2016 18:09:36 +0100 Subject: [PATCH] Fix: Set race on character creation --- app/eoceneServices/Validator.scala | 19 ++-- app/eoceneServices/eoceneSqlService.scala | 115 ++++++++++++---------- app/models/Skill.scala | 12 +-- 3 files changed, 73 insertions(+), 73 deletions(-) diff --git a/app/eoceneServices/Validator.scala b/app/eoceneServices/Validator.scala index c4da515..aa3688b 100644 --- a/app/eoceneServices/Validator.scala +++ b/app/eoceneServices/Validator.scala @@ -1,13 +1,10 @@ -/** - * ***************************************************************************** - * Copyright (c) 2014 Christian Garbers. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Simplified BSD License - * which accompanies this distribution - * - * Contributors: - * Christian Garbers - initial API and implementation - * **************************************************************************** +/* + * Copyright (c) 2016 Christian Garbers. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Simplified BSD License + * which accompanies this distribution + * Contributors: + * Christian Garbers - initial API and implementation */ package eoceneServices @@ -99,7 +96,7 @@ class Validator(char: models.Character) { def eligableForCircle(circle: Int, discipline: models.Discipline): Boolean = { val talentsOdiscipline = char.talents. filter(talent => talent.step.isDefined). - filter(talent => talent.disciplineId.get == discipline.id) + filter(talent => talent.disciplineId.getOrElse(0) == discipline.id) val nrTalents = talentsOdiscipline.size >= circleRequiremnents(circle)._1 val minRank = talentsOdiscipline.count(talent => talent.step.getOrElse(0) >= circle) >= circleRequiremnents(circle)._2 val singleTalent = talentsOdiscipline. diff --git a/app/eoceneServices/eoceneSqlService.scala b/app/eoceneServices/eoceneSqlService.scala index 578966b..26c929e 100644 --- a/app/eoceneServices/eoceneSqlService.scala +++ b/app/eoceneServices/eoceneSqlService.scala @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2016 Christian Garbers. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Simplified BSD License + * which accompanies this distribution + * Contributors: + * Christian Garbers - initial API and implementation + */ + package eoceneServices import anorm._ @@ -137,11 +146,12 @@ class eoceneSqlService extends eoceneDao{ DB.withTransaction("chars") { implicit c => val result: Boolean = SQL(eoceneSqlStrings.INSERT_CHAR).onParams(name). executeUpdate() > 0 - val char_id = getCharIdByName(name) - eoceneSqlStrings.INSERT_CHARS_USERS.onParams(char_id, + val charId = getCharIdByName(name) + changeCharRace(charId.getOrElse(0), 1) + eoceneSqlStrings.INSERT_CHARS_USERS.onParams(charId, user.main.userId).execute() eoceneUserService.updateUsersChars() - char_id + charId } } @@ -400,35 +410,6 @@ class eoceneSqlService extends eoceneDao{ } } - /** - * Remove one circle (or forget) - * - * @param id the id of the character - * @param id_talent - * @return success - */ - def corruptCharTalent(id: Int, id_talent: Int): Boolean = { - val talents = getCharTalentRowsIdByCharId(id) - val target_talent = talents.filter(a => a(1) == id_talent) - if (target_talent.size == 0) return false - val circle = getTalentCircleByTalenAndDisciId(id_talent, id) - val step = target_talent(0)(2) - val lp_cost = eoceneServices.utilities.getTalentCost(step, circle) - DB.withTransaction("chars"){implicit c=> - if (step > 1) { - SQL(eoceneSqlStrings.UPDATE_CHAR_TALENT).onParams(step - 1, id, - id_talent).executeUpdate() > 0 - SQL(eoceneSqlStrings.ADD_TO_LP).onParams(-lp_cost, id) - .executeUpdate() > 0 - } else { - SQL(eoceneSqlStrings.REMOVE_CHAR_TALENT).onParams(id, id_talent) - .executeUpdate() > 0 - SQL(eoceneSqlStrings.ADD_TO_LP).onParams(-lp_cost, id) - .executeUpdate() > 0 - } - } - } - /** * Get data for talents of a charcter * @@ -438,12 +419,11 @@ class eoceneSqlService extends eoceneDao{ * respectively */ def getCharTalentRowsIdByCharId(id: Int): List[List[Int]] = { - DB.withConnection("chars") { implicit c => - { - val querry = SQL(eoceneSqlStrings.GET_CHAR_TALENTS).onParams(id)() - return querry.map(a => List(a[Int]("id_char"), a[Int]("id_talent"), - a[Int]("step"))).toList - } + DB.withConnection("chars") { implicit c => { + val querry = SQL(eoceneSqlStrings.GET_CHAR_TALENTS).onParams(id)() + return querry.map(a => List(a[Int]("id_char"), a[Int]("id_talent"), + a[Int]("step"))).toList + } } } @@ -463,6 +443,35 @@ class eoceneSqlService extends eoceneDao{ } } + /** + * Remove one circle (or forget) + * + * @param id the id of the character + * @param id_talent + * @return success + */ + def corruptCharTalent(id: Int, id_talent: Int): Boolean = { + val talents = getCharTalentRowsIdByCharId(id) + val target_talent = talents.filter(a => a(1) == id_talent) + if (target_talent.size == 0) return false + val circle = getTalentCircleByTalenAndDisciId(id_talent, id) + val step = target_talent(0)(2) + val lp_cost = eoceneServices.utilities.getTalentCost(step, circle) + DB.withTransaction("chars") { implicit c => + if (step > 1) { + SQL(eoceneSqlStrings.UPDATE_CHAR_TALENT).onParams(step - 1, id, + id_talent).executeUpdate() > 0 + SQL(eoceneSqlStrings.ADD_TO_LP).onParams(-lp_cost, id) + .executeUpdate() > 0 + } else { + SQL(eoceneSqlStrings.REMOVE_CHAR_TALENT).onParams(id, id_talent) + .executeUpdate() > 0 + SQL(eoceneSqlStrings.ADD_TO_LP).onParams(-lp_cost, id) + .executeUpdate() > 0 + } + } + } + /** * Improve a skill (or learn it) * @@ -720,21 +729,6 @@ class eoceneSqlService extends eoceneDao{ } } - /** - * Spent Karma points - * - * @param id_char - * @param nr_points the number of karma points spent - * @return Redirect - */ - def spentKarma(id_char: Int, nr_points: Int) = { - DB.withConnection("chars"){implicit c=> - val char = getCharById(id_char) - SQL(eoceneSqlStrings.UPDATE_CHAR_ATTRIBUTE.format("kar_curr")) - .onParams(char.get.karCurr - nr_points, id_char).executeUpdate > 0 - } - } - /** * Get the id of a character with a certain name * @@ -945,6 +939,21 @@ class eoceneSqlService extends eoceneDao{ row[Option[Int]]("chars_disciplines.circle"), modifiers) } + /** + * Spent Karma points + * + * @param id_char + * @param nr_points the number of karma points spent + * @return Redirect + */ + def spentKarma(id_char: Int, nr_points: Int) = { + DB.withConnection("chars") { implicit c => + val char = getCharById(id_char) + SQL(eoceneSqlStrings.UPDATE_CHAR_ATTRIBUTE.format("kar_curr")) + .onParams(char.get.karCurr - nr_points, id_char).executeUpdate > 0 + } + } + /** * Adding legend points * diff --git a/app/models/Skill.scala b/app/models/Skill.scala index 8496fee..ed7172e 100644 --- a/app/models/Skill.scala +++ b/app/models/Skill.scala @@ -6,6 +6,7 @@ * Contributors: * Christian Garbers - initial API and implementation */ + package models @@ -37,15 +38,8 @@ case class Skill(val id: Int, val name: String, val formula: String, step match { case None => 0 //in case we have no step rank is not defined case _ => //First we do the formula attribute conversion - val rank = formulaSplit(0) match { - case "Dex" => char.derived("dex_step").asInstanceOf[Int] + step.getOrElse(0) - case "Str" => char.derived("str_step").asInstanceOf[Int] + step.getOrElse(0) - case "Tou" => char.derived("tou_step").asInstanceOf[Int] + step.getOrElse(0) - case "Cha" => char.derived("cha_step").asInstanceOf[Int] + step.getOrElse(0) - case "Per" => char.derived("dex_step").asInstanceOf[Int] + step.getOrElse(0) - case "Wil" => char.derived("wil_step").asInstanceOf[Int] + step.getOrElse(0) - case _ => 0 - } + val rank = char.derived(formulaSplit(0).toLowerCase() + "_step") + .asInstanceOf[Int] + step.getOrElse(0) //return the derived rank or add the second part of formula formulaSplit.size match { case 1 => rank